A few bugfixes.

This commit is contained in:
Olof Larsson 2011-12-14 02:06:54 +01:00
parent ff36e54e14
commit a21dd2bbc0
6 changed files with 47 additions and 20 deletions

View File

@ -2,7 +2,7 @@ name: mcore1
version: 1 version: 1
main: com.massivecraft.mcore1.MCore main: com.massivecraft.mcore1.MCore
authors: [Olof Larsson] authors: [Olof Larsson]
softdepend: [Vault, Spout] softdepend: [Spout]
commands: commands:
mcoresilenteater: mcoresilenteater:
description: ignore me. description: ignore me.

View File

@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -134,6 +136,8 @@ public class MCore extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
logPrefix = "["+this.getDescription().getName()+"] ";
// This is safe since all plugins using Persist should bukkit-depend this plugin. // This is safe since all plugins using Persist should bukkit-depend this plugin.
getPersistInstances().clear(); getPersistInstances().clear();
@ -150,4 +154,17 @@ public class MCore extends JavaPlugin
.disableHtmlEscaping() .disableHtmlEscaping()
.excludeFieldsWithModifiers(Modifier.TRANSIENT); .excludeFieldsWithModifiers(Modifier.TRANSIENT);
} }
// -------------------------------------------- //
// LOGGING
// -------------------------------------------- //
private static String logPrefix = null;
public static void log(Object... msg)
{
log(Level.INFO, msg);
}
public static void log(Level level, Object... msg)
{
Logger.getLogger("Minecraft").log(level, logPrefix + MCore.txt.implode(msg, " "));
}
} }

View File

@ -2,6 +2,7 @@ package com.massivecraft.mcore1.cmd;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.logging.Level;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -119,7 +120,7 @@ public abstract class MCommand
protected CommandSender sender; protected CommandSender sender;
public CommandSender getSender() { return this.sender; } public CommandSender getSender() { return this.sender; }
public boolean getSenderIsConsole() { return ! (this.sender instanceof Player); } public boolean getSenderIsConsole() { return ! (this.sender instanceof Player); }
public Player getMe() public Player me()
{ {
if (sender instanceof Player) if (sender instanceof Player)
{ {
@ -394,6 +395,12 @@ public abstract class MCommand
return defaultNotSet; return defaultNotSet;
} }
IArgHandler<T> handler = p().cmd.getArgHandler(clazz); IArgHandler<T> handler = p().cmd.getArgHandler(clazz);
if (handler == null)
{
MCore.log(Level.SEVERE, "There is no ArgHandler for " + clazz.getName());
}
T ret = handler.parse(this.arg(idx), style, this.sender, p()); T ret = handler.parse(this.arg(idx), style, this.sender, p());
if (ret == null) if (ret == null)
{ {
@ -408,6 +415,11 @@ public abstract class MCommand
return this.argAs(idx, clazz, null, defaultNotSet, defaultNotFound); return this.argAs(idx, clazz, null, defaultNotSet, defaultNotFound);
} }
public <T> T argAs(int idx, Class<T> clazz, String style,T defaultNotSet)
{
return this.argAs(idx, clazz, style, defaultNotSet, null);
}
public <T> T argAs(int idx, Class<T> clazz,T defaultNotSet) public <T> T argAs(int idx, Class<T> clazz,T defaultNotSet)
{ {
return this.argAs(idx, clazz, null, defaultNotSet, null); return this.argAs(idx, clazz, null, defaultNotSet, null);

View File

@ -16,7 +16,7 @@ public class AHPlayer extends AHBase<Player>
this.error = null; this.error = null;
if (str == null) return null; if (str == null) return null;
if (style.equals("match")) if (style != null && style.equals("match"))
{ {
List<Player> players = Bukkit.getServer().matchPlayer(str); List<Player> players = Bukkit.getServer().matchPlayer(str);
if (players.size() > 0) if (players.size() > 0)

View File

@ -23,7 +23,7 @@ public abstract class AHPlayerWrapper<T> extends AHBase<T>
IClassManager<T> manager = this.getManager(p); IClassManager<T> manager = this.getManager(p);
T ret; T ret;
if (style.equals("match")) if (style != null && style.equals("match"))
{ {
ret = manager.getBestMatch(str); ret = manager.getBestMatch(str);
if (ret != null) if (ret != null)

View File

@ -30,25 +30,23 @@ public class Persist
return this.classManagers; return this.classManagers;
} }
protected Timer timer = new Timer(); private Map<Class<?>, Timer> classSaveTimers = new HashMap<Class<?>, Timer>();
public synchronized <T> void setSaveInterval(Class<T> clazz, long interval)
private Map<Class<?>, SaveTask<?>> classSaveTasks = new HashMap<Class<?>, SaveTask<?>>();
@SuppressWarnings("unchecked")
public <T> void setSaveInterval(Class<T> clazz, long interval)
{ {
// Fetch the task or create a new one. // Clear old timer
SaveTask<T> task = (SaveTask<T>) this.classSaveTasks.get(clazz); Timer timer = this.classSaveTimers.get(clazz);
if (task == null) if (timer != null)
{ {
task = new SaveTask<T>(this, clazz); timer.cancel();
this.classSaveTasks.put(clazz, task); this.classSaveTimers.remove(clazz);
}
else
{
task.cancel();
} }
// Schedule the task // Create new timer
timer = new Timer();
this.classSaveTimers.put(clazz, timer);
// Add the task to the timer
SaveTask<T> task = new SaveTask<T>(this, clazz);
timer.scheduleAtFixedRate(task, interval, interval); timer.scheduleAtFixedRate(task, interval, interval);
}; };