From d09306a9b799b9089d194046075ddfa9c7e215a4 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Tue, 20 Nov 2012 08:41:41 +0100 Subject: [PATCH] experimenting... --- pom.xml | 11 ++- .../minecraft/limitedcreative/Commands.java | 6 +- .../limitedcreative/Configuration.java | 4 +- .../minecraft/limitedcreative/Core.java | 19 ++-- .../minecraft/limitedcreative/Inventory.java | 2 +- .../minecraft/limitedcreative/LCPlayer.java | 2 +- .../minecraft/limitedcreative/Perms.java | 10 ++ .../cmdblock/CommandBlocker.java | 2 +- .../limitedcreative/limits/LimitListener.java | 2 +- .../regions/RegionListener.java | 10 +- .../jaschastarke/minecraft/utils/Locale.java | 95 ------------------- src/de/jaschastarke/minecraft/utils/Util.java | 94 ------------------ .../minecraft/worldguard/CCommand.java | 8 +- .../minecraft/worldguard/CRegionManager.java | 4 +- 14 files changed, 49 insertions(+), 220 deletions(-) delete mode 100644 src/de/jaschastarke/minecraft/utils/Locale.java delete mode 100644 src/de/jaschastarke/minecraft/utils/Util.java diff --git a/pom.xml b/pom.xml index dcde083..77f85b4 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,7 @@ de.jaschastarke plib 0.1-SNAPSHOT + @@ -100,10 +101,13 @@ org.apache.maven.plugins maven-compiler-plugin - 2.0.2 + 2.3.2 1.6 1.6 + + de.jaschastarke.bukkit.maven.AnnotationProcessor + @@ -126,6 +130,9 @@ http://dev.bukkit.org/server-mods/limited-creative/ + + de.jaschastarke.minecraft.limitedcreative.Perms.Root + @@ -150,7 +157,7 @@ de.jaschastarke:plib - de/jaschastarke/bukkit/lib/maven/** + de/jaschastarke/bukkit/maven/** diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java index b2058fb..1ffc26d 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Commands.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Commands.java @@ -17,7 +17,7 @@ */ package de.jaschastarke.minecraft.limitedcreative; -import static de.jaschastarke.minecraft.utils.Locale.L; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; import static de.jaschastarke.bukkit.lib.permissions.PermissionManager.hasPermission; import java.util.Arrays; @@ -30,7 +30,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import de.jaschastarke.minecraft.utils.Util; +import de.jaschastarke.utils.StringUtil; public class Commands { private static Core plugin; @@ -48,7 +48,7 @@ public class Commands { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - Core.debug(sender.getName() + ": /" + label + " " + Util.join(args)); + Core.debug(sender.getName() + ": /" + label + " " + StringUtil.join(args)); if (args.length > 0) { Action act = null; try { diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java index 92b901f..0148bfb 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java @@ -17,8 +17,8 @@ */ package de.jaschastarke.minecraft.limitedcreative; -import static de.jaschastarke.minecraft.utils.Locale.L; -import static de.jaschastarke.minecraft.utils.Util.copyFile; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; +import static de.jaschastarke.utils.StringUtil.copyFile; import java.io.File; import java.util.ArrayList; diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Core.java b/src/de/jaschastarke/minecraft/limitedcreative/Core.java index dbe0767..0b7132f 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Core.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Core.java @@ -16,22 +16,18 @@ * along with this program. If not, see . */ package de.jaschastarke.minecraft.limitedcreative; -import static de.jaschastarke.minecraft.utils.Locale.L; import org.bukkit.event.HandlerList; import org.bukkit.plugin.PluginDescriptionFile; +import de.jaschastarke.bukkit.lib.locale.PluginLang; import de.jaschastarke.minecraft.integration.Communicator; -import de.jaschastarke.minecraft.lib.annotations.PermissionGroup; import de.jaschastarke.minecraft.limitedcreative.cmdblock.CommandBlocker; import de.jaschastarke.minecraft.limitedcreative.limits.LimitListener; import de.jaschastarke.minecraft.limitedcreative.listeners.MainListener; import de.jaschastarke.minecraft.limitedcreative.regions.WorldGuardIntegration; -import de.jaschastarke.minecraft.utils.Locale; import de.jaschastarke.minecraft.utils.Permissions; - -@PermissionGroup("limitedcreative") public class Core extends de.jaschastarke.bukkit.lib.Core { public Configuration config; public Permissions perm; @@ -46,9 +42,6 @@ public class Core extends de.jaschastarke.bukkit.lib.Core { plugin.getServer().getScheduler().cancelTasks(this); if (worldguard != null) worldguard.unload(); - try { - Locale.unload(); - } catch (NoClassDefFoundError e) {} // prevent unload issue plugin = null; worldguard = null; @@ -65,7 +58,7 @@ public class Core extends de.jaschastarke.bukkit.lib.Core { perm = new Permissions(this); com = new Communicator(this); - new Locale(this, config.getLocale()); + new PluginLang(this, config.getLocale()); spawnblock = new NoBlockItemSpawn(); @@ -128,6 +121,14 @@ public class Core extends de.jaschastarke.bukkit.lib.Core { public void error(String s) { getLog().severe("["+this.getDescription().getName()+"] " + s); } + /** + * Static localization-access only works for first locale instance. if used by another plugin, you need to + * access the Locale-Instance get-Method + */ + public static String L(String msg, Object... objects) { + return (plugin.getTranslation() != null) ? plugin.getTranslation().get(msg, objects) : msg; + } + public static void debug(String s) { if (isDebug()) plugin.info("DEBUG: " + s); diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java b/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java index cf881f9..4bd23ba 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java @@ -17,7 +17,7 @@ */ package de.jaschastarke.minecraft.limitedcreative; -import static de.jaschastarke.minecraft.utils.Locale.L; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; import org.bukkit.ChatColor; import org.bukkit.GameMode; diff --git a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java index cf5270e..f807767 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/LCPlayer.java @@ -17,7 +17,7 @@ */ package de.jaschastarke.minecraft.limitedcreative; -import static de.jaschastarke.minecraft.utils.Locale.L; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; import java.util.HashMap; import java.util.Iterator; diff --git a/src/de/jaschastarke/minecraft/limitedcreative/Perms.java b/src/de/jaschastarke/minecraft/limitedcreative/Perms.java index 91c1eb0..8a31b21 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/Perms.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/Perms.java @@ -19,12 +19,22 @@ package de.jaschastarke.minecraft.limitedcreative; import org.bukkit.permissions.PermissionDefault; +import de.jaschastarke.minecraft.lib.annotations.PermissionDescripted; import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission; import de.jaschastarke.minecraft.lib.permissions.IPermissionContainer; import de.jaschastarke.minecraft.lib.permissions.IPermission; +@PermissionDescripted(PermissionDescripted.Type.STATIC_ATTRIBUTES) public enum Perms implements IPermission { + + /** + * Test123 + */ CONFIG("config", PermissionDefault.OP), + + /** + * Test456 + */ REGIONS("regions", PermissionDefault.OP), REGIONS_BYPASS("regions_bypass", PermissionDefault.FALSE), GM("switch_gamemode", PermissionDefault.OP), diff --git a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java index 4d6a45e..d227c2b 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/cmdblock/CommandBlocker.java @@ -1,6 +1,6 @@ package de.jaschastarke.minecraft.limitedcreative.cmdblock; -import static de.jaschastarke.minecraft.utils.Locale.L; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerCommandPreprocessEvent; diff --git a/src/de/jaschastarke/minecraft/limitedcreative/limits/LimitListener.java b/src/de/jaschastarke/minecraft/limitedcreative/limits/LimitListener.java index 2fa8bbe..1fe7892 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/limits/LimitListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/limits/LimitListener.java @@ -17,7 +17,7 @@ */ package de.jaschastarke.minecraft.limitedcreative.limits; -import static de.jaschastarke.minecraft.utils.Locale.L; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; import org.bukkit.GameMode; import org.bukkit.Material; diff --git a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java index 1e80984..6e231b5 100644 --- a/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java +++ b/src/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java @@ -1,6 +1,6 @@ package de.jaschastarke.minecraft.limitedcreative.regions; -import static de.jaschastarke.minecraft.utils.Locale.L; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; import org.bukkit.GameMode; import org.bukkit.Location; @@ -18,10 +18,10 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import de.jaschastarke.bukkit.lib.Utils; import de.jaschastarke.minecraft.limitedcreative.Core; import de.jaschastarke.minecraft.limitedcreative.LCPlayer; import de.jaschastarke.minecraft.limitedcreative.Players; -import de.jaschastarke.minecraft.utils.Util; import de.jaschastarke.minecraft.worldguard.ApplicableRegions; import de.jaschastarke.minecraft.worldguard.CRegionManager; import de.jaschastarke.minecraft.worldguard.events.PlayerNewLocationAreaEvent; @@ -133,7 +133,7 @@ public class RegionListener implements Listener { Block dest = source.getRelative(event.getDirection(), i); Core.debug("dest "+i+": "+dest.getType()); if (regionSet(dest).getFlag(Flags.GAMEMODE) != GameMode.CREATIVE) { - plugin.getLog().warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Util.toString(source.getLocation()))); + plugin.getLog().warning(L("blocked.piston", source.getRelative(event.getDirection(), i - 1).getType().toString(), Utils.toString(source.getLocation()))); event.setCancelled(true); break; } else if (dest.getType() == Material.AIR) { @@ -155,12 +155,12 @@ public class RegionListener implements Listener { Core.debug("dest "+dest.getType()); if (regionSet(source).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) { if (regionSet(dest).getFlag(Flags.GAMEMODE) != GameMode.CREATIVE) { - plugin.getLog().warning(L("blocked.piston", source.getType().toString(), Util.toString(source.getLocation()))); + plugin.getLog().warning(L("blocked.piston", source.getType().toString(), Utils.toString(source.getLocation()))); event.setCancelled(true); } } else if (regionSet(dest).getFlag(Flags.GAMEMODE) == GameMode.CREATIVE) { // source isn't creative - plugin.getLog().warning(L("blocked.piston_in", source.getType().toString(), Util.toString(source.getLocation()))); + plugin.getLog().warning(L("blocked.piston_in", source.getType().toString(), Utils.toString(source.getLocation()))); event.setCancelled(true); } } diff --git a/src/de/jaschastarke/minecraft/utils/Locale.java b/src/de/jaschastarke/minecraft/utils/Locale.java deleted file mode 100644 index fd01b8b..0000000 --- a/src/de/jaschastarke/minecraft/utils/Locale.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Limited Creative - (Bukkit Plugin) - * Copyright (C) 2012 jascha@ja-s.de - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.jaschastarke.minecraft.utils; - -import java.io.File; -import java.text.MessageFormat; -import java.util.List; - -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -import de.jaschastarke.minecraft.limitedcreative.Core; - -public class Locale { - protected YamlConfiguration lang; - private YamlConfiguration fallback_lang; - private static Locale inst = null; - private JavaPlugin plugin; - private final static String DEFAULT_LANG = "en_US"; - - public Locale(JavaPlugin plugin) { - this(plugin, null); - } - - public Locale(JavaPlugin plugin, String lang) { - if (inst == null) - inst = this; - this.plugin = plugin; - if (lang == null) - lang = java.util.Locale.getDefault().toString(); - - String fn = getFilename(lang); - - Core.debug("Using Locale: " + lang); - File localefile = new File(plugin.getDataFolder(), fn); - if (localefile.exists()) - this.lang = YamlConfiguration.loadConfiguration(localefile); - else if (plugin.getResource(fn) != null) - this.lang = YamlConfiguration.loadConfiguration(plugin.getResource(fn)); - } - private String getFilename(String locale) { - return "lang/"+locale+".yml"; - } - private YamlConfiguration getLang(String msg) { - if (lang != null && lang.contains(msg)) { - return lang; - } else { - if (fallback_lang == null) - fallback_lang = YamlConfiguration.loadConfiguration(plugin.getResource(getFilename(DEFAULT_LANG))); - return fallback_lang; - } - } - public String get(String msg, Object... objects) { - YamlConfiguration lang = getLang(msg); - if (lang.contains(msg)) { - if (lang.isList(msg)) { - List list = lang.getStringList(msg); - String[] lines = new String[list.size()]; - list.toArray(lines); - msg = Util.join(lines, "\n"); - } else { - msg = lang.getString(msg); - } - } - if (objects.length > 0) - msg = MessageFormat.format(msg, objects); - return msg.replaceAll("&([0-9a-f])", "\u00A7$1"); - } - - /** - * Static localization-access only works for first locale instance. if used by another plugin, you need to - * access the Locale-Instance get-Method - */ - public static String L(String msg, Object... objects) { - return (inst != null) ? inst.get(msg, objects) : msg; - } - public static void unload() { - inst = null; - } -} diff --git a/src/de/jaschastarke/minecraft/utils/Util.java b/src/de/jaschastarke/minecraft/utils/Util.java deleted file mode 100644 index cda6270..0000000 --- a/src/de/jaschastarke/minecraft/utils/Util.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Limited Creative - (Bukkit Plugin) - * Copyright (C) 2012 jascha@ja-s.de - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package de.jaschastarke.minecraft.utils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.bukkit.Location; - -final public class Util { - public static int versionCompare(String vers1, String vers2) { - String[] v1 = vers1.split("\\."); - String[] v2 = vers2.split("\\."); - int i = 0; - while (i < v1.length && i < v2.length && v1[i].equals(v2[i])) { - i++; - } - if (i < v1.length && i < v2.length) { - int diff = new Integer(v1[i]).compareTo(new Integer(v2[i])); - return diff < 0 ? -1 : (diff == 0 ? 0 : 1); - } - return v1.length < v2.length ? -1 : (v1.length == v2.length ? 0 : 1); - } - - public static void copyFile(InputStream is, File to) { - try { - if (to.getParentFile() != null && !to.getParentFile().exists()) - to.getParentFile().mkdirs(); - OutputStream os; - os = new FileOutputStream(to); - byte[] buffer = new byte[512]; - int length; - while ((length = is.read(buffer)) > 0) { - os.write(buffer, 0, length); - } - os.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - public static void copyFile(File from, File to) { - try { - copyFile(new FileInputStream(from), to); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - public static String join(String[] list, String sep, int from, int range) { - StringBuilder result = new StringBuilder(); - for (int i = from; i >= 0 && i < from + range && i < list.length; i++) { - if (result.length() > 0) - result.append(sep); - result.append(list[i]); - } - return result.toString(); - } - public static String join(String[] list, int from, int range) { - return join(list, " ", from, range); - } - public static String join(String[] list, int from) { - return join(list, " ", from, list.length - from); - } - public static String join(String[] list) { - return join(list, " ", 0, list.length); - } - public static String join(String[] list, String sep) { - return join(list, sep, 0, list.length); - } - public static String toString(Location loc) { - return "{X: "+loc.getBlockX()+", Y: "+loc.getBlockY()+", Z: "+loc.getBlockZ()+"}"; - } -} diff --git a/src/de/jaschastarke/minecraft/worldguard/CCommand.java b/src/de/jaschastarke/minecraft/worldguard/CCommand.java index e14ac81..38f90d1 100644 --- a/src/de/jaschastarke/minecraft/worldguard/CCommand.java +++ b/src/de/jaschastarke/minecraft/worldguard/CCommand.java @@ -17,7 +17,7 @@ */ package de.jaschastarke.minecraft.worldguard; -import static de.jaschastarke.minecraft.utils.Locale.L; +import static de.jaschastarke.minecraft.limitedcreative.Core.L; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -37,7 +37,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import de.jaschastarke.minecraft.utils.Util; +import de.jaschastarke.utils.StringUtil; public class CCommand implements CommandExecutor { public enum Action { @@ -168,10 +168,10 @@ public class CCommand implements CommandExecutor { if (args.length > 3 && args[3].equalsIgnoreCase("-g")) { flag = flag.getRegionGroupFlag(); if (args.length > 4) - value = Util.join(args, 4); + value = StringUtil.join(args, 4); } else { if (args.length > 3) - value = Util.join(args, 3); + value = StringUtil.join(args, 3); } if (flag == null) { diff --git a/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java b/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java index 14a7836..1d6457d 100644 --- a/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java +++ b/src/de/jaschastarke/minecraft/worldguard/CRegionManager.java @@ -39,7 +39,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import de.jaschastarke.minecraft.limitedcreative.Core; -import de.jaschastarke.minecraft.utils.Util; +import de.jaschastarke.utils.StringUtil; public class CRegionManager { protected YamlConfiguration c; @@ -160,7 +160,7 @@ public class CRegionManager { if (ids.length > 1) { Arrays.sort(ids); } - hash.append(Util.join(ids, ",")); + hash.append(StringUtil.join(ids, ",")); } return hash.toString(); }