experimenting...
This commit is contained in:
parent
0587d6a6b7
commit
d09306a9b7
14 changed files with 49 additions and 220 deletions
11
pom.xml
11
pom.xml
|
@ -73,6 +73,7 @@
|
|||
<groupId>de.jaschastarke</groupId>
|
||||
<artifactId>plib</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<!-- <scope>compile</scope> -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -100,10 +101,13 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<annotationProcessors>
|
||||
<annotationProcessor>de.jaschastarke.bukkit.maven.AnnotationProcessor</annotationProcessor>
|
||||
</annotationProcessors>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -126,6 +130,9 @@
|
|||
<custom>
|
||||
<dev-url>http://dev.bukkit.org/server-mods/limited-creative/</dev-url>
|
||||
</custom>
|
||||
<registeredPermissions>
|
||||
<param>de.jaschastarke.minecraft.limitedcreative.Perms.Root</param>
|
||||
</registeredPermissions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@ -150,7 +157,7 @@
|
|||
<filter>
|
||||
<artifact>de.jaschastarke:plib</artifact>
|
||||
<excludes>
|
||||
<exclude>de/jaschastarke/bukkit/lib/maven/**</exclude>
|
||||
<exclude>de/jaschastarke/bukkit/maven/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,22 +16,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String> 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;
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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()+"}";
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue