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
main: com.massivecraft.mcore1.MCore
authors: [Olof Larsson]
softdepend: [Vault, Spout]
softdepend: [Spout]
commands:
mcoresilenteater:
description: ignore me.

View File

@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -117,7 +119,7 @@ public class MCore extends JavaPlugin
public static Random random = new Random();
public MCore()
{
{
this.serverListener = new MCoreServerListener(this);
this.serverListenerMonitor = new MCoreServerListenerMonitor(this);
this.playerListener = new MCorePlayerListener(this);
@ -134,6 +136,8 @@ public class MCore extends JavaPlugin
@Override
public void onEnable()
{
logPrefix = "["+this.getDescription().getName()+"] ";
// This is safe since all plugins using Persist should bukkit-depend this plugin.
getPersistInstances().clear();
@ -150,4 +154,17 @@ public class MCore extends JavaPlugin
.disableHtmlEscaping()
.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.Map.Entry;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -119,7 +120,7 @@ public abstract class MCommand
protected CommandSender sender;
public CommandSender getSender() { return this.sender; }
public boolean getSenderIsConsole() { return ! (this.sender instanceof Player); }
public Player getMe()
public Player me()
{
if (sender instanceof Player)
{
@ -394,6 +395,12 @@ public abstract class MCommand
return defaultNotSet;
}
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());
if (ret == null)
{
@ -408,6 +415,11 @@ public abstract class MCommand
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)
{
return this.argAs(idx, clazz, null, defaultNotSet, null);

View File

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

View File

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

View File

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