Logging with color and improvement to Colls.
This commit is contained in:
parent
d27473a8ad
commit
a47df27b30
@ -4,6 +4,8 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -37,7 +39,10 @@ public abstract class MPlugin extends JavaPlugin implements Listener
|
|||||||
public boolean preEnable()
|
public boolean preEnable()
|
||||||
{
|
{
|
||||||
timeEnableStart = System.currentTimeMillis();
|
timeEnableStart = System.currentTimeMillis();
|
||||||
this.logPrefix = "["+this.getDescription().getFullName()+"] ";
|
|
||||||
|
this.logPrefixColored = Txt.parse("<teal>[<aqua>%s %s<teal>] <i>", this.getDescription().getName(), this.getDescription().getVersion());
|
||||||
|
this.logPrefixPlain = ChatColor.stripColor(this.logPrefixColored);
|
||||||
|
|
||||||
log("=== ENABLE START ===");
|
log("=== ENABLE START ===");
|
||||||
|
|
||||||
// Create Gson
|
// Create Gson
|
||||||
@ -54,7 +59,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
|
|||||||
|
|
||||||
public void postEnable()
|
public void postEnable()
|
||||||
{
|
{
|
||||||
log("=== ENABLE DONE (Took "+(System.currentTimeMillis()-timeEnableStart)+"ms) ===");
|
log(Txt.parse("=== ENABLE <g>COMPLELTE <i>(Took <h>"+(System.currentTimeMillis()-timeEnableStart)+"ms<i>) ==="));
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -94,7 +99,7 @@ public abstract class MPlugin extends JavaPlugin implements Listener
|
|||||||
|
|
||||||
public void suicide()
|
public void suicide()
|
||||||
{
|
{
|
||||||
log("Now I suicide!");
|
log(Txt.parse("<b>Now I suicide!"));
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,13 +114,23 @@ public abstract class MPlugin extends JavaPlugin implements Listener
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// LOGGING
|
// LOGGING
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
private String logPrefix = null;
|
private String logPrefixColored = null;
|
||||||
|
private String logPrefixPlain = null;
|
||||||
public void log(Object... msg)
|
public void log(Object... msg)
|
||||||
{
|
{
|
||||||
log(Level.INFO, msg);
|
log(Level.INFO, msg);
|
||||||
}
|
}
|
||||||
public void log(Level level, Object... msg)
|
public void log(Level level, Object... msg)
|
||||||
{
|
{
|
||||||
Logger.getLogger("Minecraft").log(level, this.logPrefix + Txt.implode(msg, " "));
|
String imploded = Txt.implode(msg, " ");
|
||||||
|
ConsoleCommandSender sender = Bukkit.getConsoleSender();
|
||||||
|
if (level == Level.INFO && sender != null)
|
||||||
|
{
|
||||||
|
Bukkit.getConsoleSender().sendMessage(this.logPrefixColored + imploded);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.getLogger("Minecraft").log(level, this.logPrefixPlain + imploded);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ public class ARUniverse implements ArgReader<String>
|
|||||||
result.getErrors().add("<b>No universe \"<h>"+str+"<b>\" exists in multiverse <h>"+this.multiverse.getId()+"<b>.");
|
result.getErrors().add("<b>No universe \"<h>"+str+"<b>\" exists in multiverse <h>"+this.multiverse.getId()+"<b>.");
|
||||||
|
|
||||||
Collection<String> names = new ArrayList<String>(multiverse.getUniverses());
|
Collection<String> names = new ArrayList<String>(multiverse.getUniverses());
|
||||||
names.add(Multiverse.DEFAULT);
|
|
||||||
result.getErrors().add("<i>Use "+Txt.implodeCommaAndDot(names, "<h>%s", "<i>, ", " <i>or ", "<i>."));
|
result.getErrors().add("<i>Use "+Txt.implodeCommaAndDot(names, "<h>%s", "<i>, ", " <i>or ", "<i>."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.event.server.PluginEnableEvent;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.massivecraft.mcore4.MPlugin;
|
import com.massivecraft.mcore4.MPlugin;
|
||||||
|
import com.massivecraft.mcore4.util.Txt;
|
||||||
|
|
||||||
public class Integration implements Listener
|
public class Integration implements Listener
|
||||||
{
|
{
|
||||||
@ -49,11 +50,11 @@ public class Integration implements Listener
|
|||||||
{
|
{
|
||||||
this.features.activate();
|
this.features.activate();
|
||||||
this.active = true;
|
this.active = true;
|
||||||
this.ourPlugin.log("Activated integration with "+this.features.getTargetPluginName()+".");
|
this.ourPlugin.log(Txt.parse("<g>Activated <i>integration with <h>%s<i>.", this.features.getTargetPluginName()));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
this.ourPlugin.log("Failed to activate integration with "+this.features.getTargetPluginName()+".");
|
this.ourPlugin.log(Txt.parse("<b>Failed to activate <i>integration with <h>%s<i>.", this.features.getTargetPluginName()));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,11 +67,11 @@ public class Integration implements Listener
|
|||||||
{
|
{
|
||||||
this.active = false;
|
this.active = false;
|
||||||
this.features.deactivate();
|
this.features.deactivate();
|
||||||
this.ourPlugin.log("Deactivated integration with "+this.features.getTargetPluginName()+".");
|
this.ourPlugin.log(Txt.parse("Deactivated integration with <h>%s<i>.", this.features.getTargetPluginName()));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
this.ourPlugin.log("Failed to deactivate integration with "+this.features.getTargetPluginName()+".");
|
this.ourPlugin.log(Txt.parse("<b>Failed to deactivate <i>integration with <h>%s<i>.", this.features.getTargetPluginName()));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.massivecraft.mcore4.store;
|
package com.massivecraft.mcore4.store;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.massivecraft.mcore4.usys.Aspect;
|
import com.massivecraft.mcore4.usys.Aspect;
|
||||||
@ -9,27 +11,28 @@ import com.massivecraft.mcore4.util.MUtil;
|
|||||||
public abstract class Colls<C extends Coll<E, L>, E, L>
|
public abstract class Colls<C extends Coll<E, L>, E, L>
|
||||||
{
|
{
|
||||||
protected Map<String, C> name2coll = new HashMap<String, C>();
|
protected Map<String, C> name2coll = new HashMap<String, C>();
|
||||||
public Map<String, C> name2coll() { return this.name2coll; }
|
|
||||||
|
|
||||||
public abstract C createColl(String name);
|
public abstract C createColl(String name);
|
||||||
|
|
||||||
public abstract Aspect aspect();
|
public abstract Aspect aspect();
|
||||||
public abstract String basename();
|
public abstract String basename();
|
||||||
|
|
||||||
public abstract Db<?> getDb();
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
String start = this.collnameForUniverse("");
|
this.getColls();
|
||||||
for (String collname : this.getDb().collnames())
|
|
||||||
{
|
|
||||||
if ( ! collname.startsWith(start)) continue;
|
|
||||||
this.getForCollname(collname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<C> getColls()
|
||||||
|
{
|
||||||
|
List<C> ret = new ArrayList<C>();
|
||||||
|
for (String universe : this.aspect().multiverse().getUniverses())
|
||||||
|
{
|
||||||
|
ret.add(this.getForUniverse(universe));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -5,6 +5,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import com.massivecraft.mcore4.store.Entity;
|
import com.massivecraft.mcore4.store.Entity;
|
||||||
|
import com.massivecraft.mcore4.xlib.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public class Aspect extends Entity<Aspect, String>
|
public class Aspect extends Entity<Aspect, String>
|
||||||
{
|
{
|
||||||
@ -40,6 +41,7 @@ public class Aspect extends Entity<Aspect, String>
|
|||||||
// STORED FIELDS
|
// STORED FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@SerializedName("mid")
|
||||||
protected String multiverseId;
|
protected String multiverseId;
|
||||||
public String multiverseId() { return this.multiverseId; }
|
public String multiverseId() { return this.multiverseId; }
|
||||||
public void multiverseId(String val) { this.multiverseId = val; }
|
public void multiverseId(String val) { this.multiverseId = val; }
|
||||||
|
@ -2,6 +2,7 @@ package com.massivecraft.mcore4.usys;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -66,11 +67,12 @@ public class Multiverse extends Entity<Multiverse, String>
|
|||||||
|
|
||||||
public boolean containsUniverse(String worldName)
|
public boolean containsUniverse(String worldName)
|
||||||
{
|
{
|
||||||
return worldName.equals(Multiverse.DEFAULT) || this.uw.containsKey(worldName);
|
return this.getUniverses().contains(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> newUniverse(String universe)
|
public Set<String> newUniverse(String universe)
|
||||||
{
|
{
|
||||||
|
if (universe.equals(Multiverse.DEFAULT)) return null;
|
||||||
Set<String> ret = this.uw.get(universe);
|
Set<String> ret = this.uw.get(universe);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
@ -87,7 +89,10 @@ public class Multiverse extends Entity<Multiverse, String>
|
|||||||
|
|
||||||
public Set<String> getUniverses()
|
public Set<String> getUniverses()
|
||||||
{
|
{
|
||||||
return this.uw.keySet();
|
Set<String> ret = new LinkedHashSet<String>();
|
||||||
|
ret.addAll(this.uw.keySet());
|
||||||
|
ret.add(Multiverse.DEFAULT);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUniverseForWorldName(String worldName)
|
public String getUniverseForWorldName(String worldName)
|
||||||
|
@ -30,16 +30,9 @@ public class CmdUsysMultiverseList extends UsysCommand
|
|||||||
List<String> lines = new ArrayList<String>();
|
List<String> lines = new ArrayList<String>();
|
||||||
|
|
||||||
for (Multiverse multiverse : MultiverseColl.i.getAll())
|
for (Multiverse multiverse : MultiverseColl.i.getAll())
|
||||||
{
|
|
||||||
if (multiverse.getUniverses().size() > 0)
|
|
||||||
{
|
{
|
||||||
lines.add("<h>"+multiverse.getId()+" <i>has "+Txt.implodeCommaAndDot(multiverse.getUniverses(), "<aqua>%s", "<i>, ", " <i>and ", "<i>."));
|
lines.add("<h>"+multiverse.getId()+" <i>has "+Txt.implodeCommaAndDot(multiverse.getUniverses(), "<aqua>%s", "<i>, ", " <i>and ", "<i>."));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
lines.add("<h>"+multiverse.getId()+" <i>has no universes.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send them
|
// Send them
|
||||||
lines = Txt.parseWrap(lines);
|
lines = Txt.parseWrap(lines);
|
||||||
|
@ -30,9 +30,9 @@ public class CmdUsysMultiverseShow extends UsysCommand
|
|||||||
|
|
||||||
for (String universe : multiverse.getUniverses())
|
for (String universe : multiverse.getUniverses())
|
||||||
{
|
{
|
||||||
|
if (universe.equals(Multiverse.DEFAULT)) continue;
|
||||||
msg("<aqua>"+universe+"<i>: "+Txt.implodeCommaAndDot(multiverse.getWorlds(universe), "<h>%s", "<i>, ", " <i>and ", "<i>."));
|
msg("<aqua>"+universe+"<i>: "+Txt.implodeCommaAndDot(multiverse.getWorlds(universe), "<h>%s", "<i>, ", " <i>and ", "<i>."));
|
||||||
}
|
}
|
||||||
|
|
||||||
msg("<aqua>default<i>: for all other worlds.");
|
msg("<aqua>default<i>: for all other worlds.");
|
||||||
|
|
||||||
msg("");
|
msg("");
|
||||||
|
@ -24,7 +24,7 @@ public class CmdUsysUniverseNew extends UsysCommand
|
|||||||
|
|
||||||
String universe = this.arg(0);
|
String universe = this.arg(0);
|
||||||
|
|
||||||
if (multiverse.containsUniverse(universe) || universe.equals(Multiverse.DEFAULT))
|
if (multiverse.containsUniverse(universe))
|
||||||
{
|
{
|
||||||
msg("<b>The universe <h>%s<b> already exists in multiverse <h>%s<b>.", universe, multiverse.getId());
|
msg("<b>The universe <h>%s<b> already exists in multiverse <h>%s<b>.", universe, multiverse.getId());
|
||||||
return;
|
return;
|
||||||
|
@ -2,6 +2,7 @@ package com.massivecraft.mcore4.util;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -148,6 +149,18 @@ public class MUtil
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// LE NICE RANDOM
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static <T> T random(Collection<T> coll)
|
||||||
|
{
|
||||||
|
if (coll.size() == 0) return null;
|
||||||
|
if (coll.size() == 1) return coll.iterator().next();
|
||||||
|
int index = MCore.random.nextInt(coll.size());
|
||||||
|
return new ArrayList<T>(coll).get(index);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// SORTING
|
// SORTING
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -98,6 +98,7 @@ public class Txt
|
|||||||
parseReplacements.put("<p>", "\u00A73");
|
parseReplacements.put("<p>", "\u00A73");
|
||||||
parseReplacements.put("<parameter>", "\u00A73");
|
parseReplacements.put("<parameter>", "\u00A73");
|
||||||
parseReplacements.put("&&", "&");
|
parseReplacements.put("&&", "&");
|
||||||
|
parseReplacements.put("§§", "§");
|
||||||
|
|
||||||
// Color by number/char
|
// Color by number/char
|
||||||
for (int i = 48; i <= 122; i++)
|
for (int i = 48; i <= 122; i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user