Merge pull request #68 from GenialJerome/1.6.x

Faction Disband Reason & Auto-Completion
This commit is contained in:
Naman 2018-12-08 22:56:23 -06:00 committed by GitHub
commit c68047b498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 365 additions and 403 deletions

View File

@ -345,7 +345,6 @@ public class Conf {
territoryEnemyDenyCommands.add("tpaccept"); territoryEnemyDenyCommands.add("tpaccept");
territoryEnemyDenyCommands.add("tpa"); territoryEnemyDenyCommands.add("tpa");
territoryProtectedMaterials.add(SavageFactions.plugin.WOODEN_DOOR); territoryProtectedMaterials.add(SavageFactions.plugin.WOODEN_DOOR);
territoryProtectedMaterials.add(SavageFactions.plugin.TRAP_DOOR); territoryProtectedMaterials.add(SavageFactions.plugin.TRAP_DOOR);
territoryProtectedMaterials.add(SavageFactions.plugin.FENCE_GATE); territoryProtectedMaterials.add(SavageFactions.plugin.FENCE_GATE);
@ -443,7 +442,7 @@ public class Conf {
public enum Backend { public enum Backend {
JSON, JSON,
//MYSQL, TODO //MYSQL, TODO add MySQL storage
; ;
} }
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.struct.BanInfo; import com.massivecraft.factions.struct.BanInfo;
@ -204,6 +205,8 @@ public interface Faction extends EconomyParticipator {
void disband(Player disbander); void disband(Player disbander);
void disband(Player disbander, PlayerDisbandReason reason);
// ------------------------------- // -------------------------------
// Relation and relation colors // Relation and relation colors
// ------------------------------- // -------------------------------
@ -283,6 +286,8 @@ public interface Faction extends EconomyParticipator {
// promotes new leader, or disbands faction if no other members left // promotes new leader, or disbands faction if no other members left
void promoteNewLeader(); void promoteNewLeader();
void promoteNewLeader(boolean autoLeave);
Role getDefaultRole(); Role getDefaultRole();
void setDefaultRole(Role role); void setDefaultRole(Role role);

View File

@ -12,6 +12,8 @@ import com.massivecraft.factions.listeners.*;
import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.util.*; import com.massivecraft.factions.util.*;
import com.massivecraft.factions.util.Particles.ReflectionUtils; import com.massivecraft.factions.util.Particles.ReflectionUtils;
import com.massivecraft.factions.zcore.CommandVisibility;
import com.massivecraft.factions.zcore.MCommand;
import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.MPlugin;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable; import com.massivecraft.factions.zcore.fperms.Permissable;
@ -30,6 +32,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -42,6 +45,7 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors;
public class SavageFactions extends MPlugin { public class SavageFactions extends MPlugin {
@ -74,6 +78,8 @@ public class SavageFactions extends MPlugin {
private ClipPlaceholderAPIManager clipPlaceholderAPIManager; private ClipPlaceholderAPIManager clipPlaceholderAPIManager;
private boolean mvdwPlaceholderAPIManager = false; private boolean mvdwPlaceholderAPIManager = false;
private Listener[] eventsListener;
public SavageFactions() { public SavageFactions() {
plugin = this; plugin = this;
} }
@ -117,18 +123,10 @@ public class SavageFactions extends MPlugin {
// Vault dependency check. // Vault dependency check.
if (SavageFactions.plugin.getServer().getPluginManager().getPlugin("Vault") == null) { if (getServer().getPluginManager().getPlugin("Vault") == null) {
SavageFactions.plugin.log("Vault is not present, the plugin will not run properly."); log("Vault is not present, the plugin will not run properly.");
this.onDisable(); getServer().getPluginManager().disablePlugin(plugin);
Bukkit.getScheduler().scheduleSyncDelayedTask(this,
new Runnable() {
@Override
public void run() {
SavageFactions.plugin.getServer().getPluginManager().disablePlugin(SavageFactions.plugin);
}
}, 20L);
return; return;
} }
int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]); int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]);
@ -154,13 +152,13 @@ public class SavageFactions extends MPlugin {
saveDefaultConfig(); saveDefaultConfig();
// Load Conf from disk // Load Conf from disk
Conf.load(); Conf.load();
Essentials.setup(); Essentials.setup();
hookedPlayervaults = setupPlayervaults(); hookedPlayervaults = setupPlayervaults();
FPlayers.getInstance().load(); FPlayers.getInstance().load();
Factions.getInstance().load(); Factions.getInstance().load();
for (FPlayer fPlayer : FPlayers.getInstance().getAllFPlayers()) { for (FPlayer fPlayer : FPlayers.getInstance().getAllFPlayers()) {
Faction faction = Factions.getInstance().getFactionById(fPlayer.getFactionId()); Faction faction = Factions.getInstance().getFactionById(fPlayer.getFactionId());
if (faction == null) { if (faction == null) {
@ -170,10 +168,10 @@ public class SavageFactions extends MPlugin {
} }
faction.addFPlayer(fPlayer); faction.addFPlayer(fPlayer);
} }
Board.getInstance().load(); Board.getInstance().load();
Board.getInstance().clean(); Board.getInstance().clean();
// Add Base Commands // Add Base Commands
this.cmdBase = new FCmdRoot(); this.cmdBase = new FCmdRoot();
this.cmdAutoHelp = new CmdAutoHelp(); this.cmdAutoHelp = new CmdAutoHelp();
@ -196,32 +194,37 @@ public class SavageFactions extends MPlugin {
new MassiveStats(this); new MassiveStats(this);
} }
if (version > 8) { if (version > 8) {
useNonPacketParticles = true; useNonPacketParticles = true;
SavageFactions.plugin.log("Minecraft Version 1.9 or higher found, using non packet based particle API"); log("Minecraft Version 1.9 or higher found, using non packet based particle API");
} }
if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) { if (getConfig().getBoolean("enable-faction-flight")) {
factionsFlight = true; factionsFlight = true;
} }
// Register Event Handlers // Register Event Handlers
getServer().getPluginManager().registerEvents(new FactionsPlayerListener(this), this); eventsListener = new Listener[] {
getServer().getPluginManager().registerEvents(new FactionsChatListener(this), this); new FactionsPlayerListener(this),
getServer().getPluginManager().registerEvents(new FactionsEntityListener(this), this); new FactionsChatListener(this),
getServer().getPluginManager().registerEvents(new FactionsExploitListener(), this); new FactionsEntityListener(this),
getServer().getPluginManager().registerEvents(new FactionsBlockListener(this), this); new FactionsExploitListener(),
getServer().getPluginManager().registerEvents(new FUpgradesGUI(), this); new FactionsBlockListener(this),
getServer().getPluginManager().registerEvents(new EXPUpgrade(), this); new FUpgradesGUI(),
getServer().getPluginManager().registerEvents(new CropUpgrades(), this); new EXPUpgrade(),
getServer().getPluginManager().registerEvents(new SpawnerUpgrades(), this); new CropUpgrades(),
// since some other plugins execute commands directly through this command interface, provide it new SpawnerUpgrades(),
this.getCommand(this.refCommand).setExecutor(this); };
if (SavageFactions.plugin.getDescription().getFullName().contains("BETA")) { for (Listener eventListener: eventsListener)
getServer().getPluginManager().registerEvents(eventListener, this);
// since some other plugins execute commands directly through this command interface, provide it
getCommand(this.refCommand).setExecutor(this);
getCommand(this.refCommand).setTabCompleter(this);
if (getDescription().getFullName().contains("BETA")) {
divider(); divider();
System.out.println("You are using a BETA version of the plugin!"); System.out.println("You are using a BETA version of the plugin!");
System.out.println("This comes with risks of small bugs in newer features!"); System.out.println("This comes with risks of small bugs in newer features!");
@ -229,7 +232,6 @@ public class SavageFactions extends MPlugin {
divider(); divider();
} }
this.setupPlaceholderAPI(); this.setupPlaceholderAPI();
this.postEnable(); this.postEnable();
this.loadSuccessful = true; this.loadSuccessful = true;
@ -311,8 +313,9 @@ public class SavageFactions extends MPlugin {
} }
private void migrateFPlayerLeaders() { private void migrateFPlayerLeaders() {
List<String> lines = new ArrayList<String>(); List<String> lines = new ArrayList<>();
File fplayerFile = new File("plugins\\Factions\\players.json"); File fplayerFile = new File("plugins\\Factions\\players.json");
try { try {
BufferedReader br = new BufferedReader(new FileReader(fplayerFile)); BufferedReader br = new BufferedReader(new FileReader(fplayerFile));
System.out.println("Migrating old players.json file."); System.out.println("Migrating old players.json file.");
@ -335,26 +338,17 @@ public class SavageFactions extends MPlugin {
System.out.println("File was not found for players.json, assuming" System.out.println("File was not found for players.json, assuming"
+ " there is no need to migrate old players.json file."); + " there is no need to migrate old players.json file.");
} }
} }
private void changeItemIDSInConfig() { private void changeItemIDSInConfig() {
log("Starting conversion of legacy material in config to 1.13 materials.");
SavageFactions.plugin.log("Starting conversion of legacy material in config to 1.13 materials.");
replaceStringInConfig("fperm-gui.relation.materials.recruit", "WOOD_SWORD", "WOODEN_SWORD"); replaceStringInConfig("fperm-gui.relation.materials.recruit", "WOOD_SWORD", "WOODEN_SWORD");
replaceStringInConfig("fperm-gui.relation.materials.normal", "GOLD_SWORD", "GOLDEN_SWORD"); replaceStringInConfig("fperm-gui.relation.materials.normal", "GOLD_SWORD", "GOLDEN_SWORD");
replaceStringInConfig("fperm-gui.relation.materials.ally", "GOLD_AXE", "GOLDEN_AXE"); replaceStringInConfig("fperm-gui.relation.materials.ally", "GOLD_AXE", "GOLDEN_AXE");
replaceStringInConfig("fperm-gui.relation.materials.neutral", "WOOD_AXE", "WOODEN_AXE"); replaceStringInConfig("fperm-gui.relation.materials.neutral", "WOOD_AXE", "WOODEN_AXE");
ConfigurationSection actionMaterialsConfigSection = getConfig().getConfigurationSection("fperm-gui.action.materials"); ConfigurationSection actionMaterialsConfigSection = getConfig().getConfigurationSection("fperm-gui.action.materials");
Set<String> actionMaterialKeys = actionMaterialsConfigSection.getKeys(true); Set<String> actionMaterialKeys = actionMaterialsConfigSection.getKeys(true);
@ -363,27 +357,20 @@ public class SavageFactions extends MPlugin {
} }
replaceStringInConfig("fperm-gui.dummy-items.0.material", "STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE"); replaceStringInConfig("fperm-gui.dummy-items.0.material", "STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE");
replaceStringInConfig("fwarp-gui.dummy-items.0.material", "STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE"); replaceStringInConfig("fwarp-gui.dummy-items.0.material", "STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE");
replaceStringInConfig("fupgrades.MainMenu.DummyItem.Type", "STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE"); replaceStringInConfig("fupgrades.MainMenu.DummyItem.Type", "STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE");
replaceStringInConfig("fupgrades.MainMenu.EXP.EXPItem.Type", "EXP_BOTTLE", "EXPERIENCE_BOTTLE"); replaceStringInConfig("fupgrades.MainMenu.EXP.EXPItem.Type", "EXP_BOTTLE", "EXPERIENCE_BOTTLE");
replaceStringInConfig("fupgrades.MainMenu.Spawners.SpawnerItem.Type", "MOB_SPAWNER", "SPAWNER"); replaceStringInConfig("fupgrades.MainMenu.Spawners.SpawnerItem.Type", "MOB_SPAWNER", "SPAWNER");
replaceStringInConfig("fperm-gui.action.access.allow", "LIME", "LIME_STAINED_GLASS"); replaceStringInConfig("fperm-gui.action.access.allow", "LIME", "LIME_STAINED_GLASS");
replaceStringInConfig("fperm-gui.action.access.deny", "RED", "RED_STAINED_GLASS"); replaceStringInConfig("fperm-gui.action.access.deny", "RED", "RED_STAINED_GLASS");
replaceStringInConfig("fperm-gui.action.access.undefined", "CYAN", "CYAN_STAINED_GLASS"); replaceStringInConfig("fperm-gui.action.access.undefined", "CYAN", "CYAN_STAINED_GLASS");
} }
public void replaceStringInConfig(String path, String stringToReplace, String replacementString) { public void replaceStringInConfig(String path, String stringToReplace, String replacementString) {
if (getConfig().getString(path).equals(stringToReplace)) { if (getConfig().getString(path).equals(stringToReplace)) {
SavageFactions.plugin.log("Replacing legacy material '" + stringToReplace + "' with '" + replacementString + "' for config node '" + path + "'."); log("Replacing legacy material '" + stringToReplace + "' with '" + replacementString + "' for config node '" + path + "'.");
getConfig().set(path, replacementString); getConfig().set(path, replacementString);
} }
} }
@ -516,6 +503,53 @@ public class SavageFactions extends MPlugin {
return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false); return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false);
} }
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args){
List<String> completions = new ArrayList<>();
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
List<String> argsList = new ArrayList<>(Arrays.asList(args));
argsList.remove(argsList.size() - 1);
String cmdValid = (cmd + " " + TextUtil.implode(argsList, " ")).trim();
MCommand<?> commandEx = cmdBase;
List<MCommand<?>> commandsList = cmdBase.subCommands;
for (; !commandsList.isEmpty() && !argsList.isEmpty(); argsList.remove(0))
{
String cmdName = argsList.get(0).toLowerCase();
MCommand<?> commandFounded = commandsList.stream()
.filter(c -> c.aliases.contains(cmdName))
.findFirst().orElse(null);
if (commandFounded != null)
{
commandEx = commandFounded;
commandsList = commandFounded.subCommands;
}
else break;
}
if (argsList.isEmpty())
{
for (MCommand<?> subCommand: commandEx.subCommands)
{
subCommand.setCommandSender(sender);
if (handleCommand(sender, cmdValid + " " + subCommand.aliases.get(0), true)
&& subCommand.visibility != CommandVisibility.INVISIBLE
&& subCommand.validSenderType(sender, false)
&& subCommand.validSenderPermissions(sender, false))
completions.addAll(subCommand.aliases);
}
}
String lastArg = args[args.length - 1].toLowerCase();
completions = completions.stream()
.filter(m -> m.toLowerCase().startsWith(lastArg))
.collect(Collectors.toList());
return completions;
}
public void createTimedHologram(final Location location, String text, Long timeout) { public void createTimedHologram(final Location location, String text, Long timeout) {
ArmorStand as = (ArmorStand) location.add(0.5, 1, 0.5).getWorld().spawnEntity(location, EntityType.ARMOR_STAND); //Spawn the ArmorStand ArmorStand as = (ArmorStand) location.add(0.5, 1, 0.5).getWorld().spawnEntity(location, EntityType.ARMOR_STAND); //Spawn the ArmorStand
as.setVisible(false); //Makes the ArmorStand invisible as.setVisible(false); //Makes the ArmorStand invisible
@ -524,12 +558,12 @@ public class SavageFactions extends MPlugin {
as.setCustomName(SavageFactions.plugin.color(text)); //Set this to the text you want as.setCustomName(SavageFactions.plugin.color(text)); //Set this to the text you want
as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not as.setCustomNameVisible(true); //This makes the text appear no matter if your looking at the entity or not
final ArmorStand armorStand = as; final ArmorStand armorStand = as;
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> {
armorStand.remove(); armorStand.remove();
getLogger().info("Removing Hologram."); getLogger().info("Removing Hologram.");
} }
, timeout * 20); , timeout * 20);
} }

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.SavageFactions; import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.Access;
@ -43,9 +44,6 @@ public class CmdDisband extends FCommand {
return; return;
} }
boolean isMyFaction = fme != null && faction == myFaction;
if (!fme.isAdminBypassing()) { if (!fme.isAdminBypassing()) {
Access access = faction.getAccess(fme, PermissableAction.DISBAND); Access access = faction.getAccess(fme, PermissableAction.DISBAND);
if (fme.getRole() != Role.LEADER && access != Access.ALLOW) { if (fme.getRole() != Role.LEADER && access != Access.ALLOW) {
@ -78,11 +76,9 @@ public class CmdDisband extends FCommand {
} else { } else {
//Check if the faction we asked confirmation for is the one being disbanded. //Check if the faction we asked confirmation for is the one being disbanded.
if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) { if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) {
faction.disband(me); faction.disband(me, PlayerDisbandReason.COMMAND);
} }
} }
} }
@Override @Override

View File

@ -44,7 +44,9 @@ public abstract class FCommand extends MCommand<SavageFactions> {
} }
@Override @Override
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) { public void setCommandSender(CommandSender sender)
{
super.setCommandSender(sender);
if (sender instanceof Player) { if (sender instanceof Player) {
this.fme = FPlayers.getInstance().getByPlayer((Player) sender); this.fme = FPlayers.getInstance().getByPlayer((Player) sender);
this.myFaction = this.fme.getFaction(); this.myFaction = this.fme.getFaction();
@ -52,6 +54,11 @@ public abstract class FCommand extends MCommand<SavageFactions> {
this.fme = null; this.fme = null;
this.myFaction = null; this.myFaction = null;
} }
}
@Override
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
setCommandSender(sender);
super.execute(sender, args, commandChain); super.execute(sender, args, commandChain);
} }

View File

@ -12,11 +12,13 @@ import org.bukkit.event.Cancellable;
public class FactionDisbandEvent extends FactionEvent implements Cancellable { public class FactionDisbandEvent extends FactionEvent implements Cancellable {
private boolean cancelled = false; private boolean cancelled = false;
private Player sender; private final Player sender;
private final PlayerDisbandReason reason;
public FactionDisbandEvent(Player sender, String factionId) { public FactionDisbandEvent(Player sender, String factionId, PlayerDisbandReason reason) {
super(Factions.getInstance().getFactionById(factionId)); super(Factions.getInstance().getFactionById(factionId));
this.sender = sender; this.sender = sender;
this.reason = reason;
} }
public FPlayer getFPlayer() { public FPlayer getFPlayer() {
@ -27,6 +29,10 @@ public class FactionDisbandEvent extends FactionEvent implements Cancellable {
return sender; return sender;
} }
public PlayerDisbandReason getReason() {
return reason;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
@ -36,4 +42,11 @@ public class FactionDisbandEvent extends FactionEvent implements Cancellable {
public void setCancelled(boolean c) { public void setCancelled(boolean c) {
cancelled = c; cancelled = c;
} }
public enum PlayerDisbandReason {
COMMAND,
PLUGIN,
INACTIVITY,
LEAVE,
}
} }

View File

@ -29,6 +29,7 @@ public class FactionEvent extends Event {
return this.faction; return this.faction;
} }
@Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
} }

View File

@ -3,7 +3,6 @@ package com.massivecraft.factions.scoreboards;
import com.massivecraft.factions.*; import com.massivecraft.factions.*;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import net.milkbowl.vault.chat.Chat;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;

View File

@ -63,7 +63,7 @@ public class AutoLeaveProcessTask extends BukkitRunnable {
if (fplayer.getRole() == Role.LEADER) { if (fplayer.getRole() == Role.LEADER) {
Faction faction = fplayer.getFaction(); Faction faction = fplayer.getFaction();
if (faction != null) { if (faction != null) {
fplayer.getFaction().promoteNewLeader(); fplayer.getFaction().promoteNewLeader(true);
} }
} }

View File

@ -20,7 +20,7 @@ public class MiscUtil {
/// TODO create tag whitelist!! /// TODO create tag whitelist!!
public static HashSet<String> substanceChars = public static HashSet<String> substanceChars =
new HashSet<>(Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")); new HashSet<>(Arrays.asList("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("")));
public static EntityType creatureTypeFromEntity(Entity entity) { public static EntityType creatureTypeFromEntity(Entity entity) {
if (!(entity instanceof Creature)) { if (!(entity instanceof Creature)) {
@ -100,25 +100,11 @@ public class MiscUtil {
} }
switch (player.getRole()) { switch (player.getRole()) {
case LEADER: case LEADER: admins.add(player); break;
admins.add(player); case COLEADER: admins.add(player); break;
break; case MODERATOR: moderators.add(player); break;
case NORMAL: normal.add(player); break;
case COLEADER: case RECRUIT: recruit.add(player); break;
admins.add(player);
break;
case MODERATOR:
moderators.add(player);
break;
case NORMAL:
normal.add(player);
break;
case RECRUIT:
recruit.add(player);
break;
} }
} }

View File

@ -858,6 +858,7 @@ public enum MultiversionMaterials {
ZOMBIE_VILLAGER_SPAWN_EGG("MONSTER_EGG", 0), ZOMBIE_VILLAGER_SPAWN_EGG("MONSTER_EGG", 0),
ZOMBIE_WALL_HEAD("SKULL", 0), ZOMBIE_WALL_HEAD("SKULL", 0),
; ;
static int newV = - 1; static int newV = - 1;
private static HashMap<String, MultiversionMaterials> cachedSearch = new HashMap<>(); private static HashMap<String, MultiversionMaterials> cachedSearch = new HashMap<>();
String m; String m;
@ -871,11 +872,13 @@ public enum MultiversionMaterials {
public static boolean isNewVersion() { public static boolean isNewVersion() {
if (newV == 0) return false; if (newV == 0) return false;
if (newV == 1) return true; if (newV == 1) return true;
Material mat = Material.matchMaterial("RED_WOOL"); Material mat = Material.matchMaterial("RED_WOOL");
if (mat != null) { if (mat != null) {
newV = 1; newV = 1;
return true; return true;
} }
newV = 0; newV = 0;
return false; return false;
} }
@ -894,20 +897,13 @@ public enum MultiversionMaterials {
} }
public static MultiversionMaterials fromString(String key) { public static MultiversionMaterials fromString(String key) {
MultiversionMaterials xmat = null;
try { try {
xmat = MultiversionMaterials.valueOf(key); return MultiversionMaterials.valueOf(key);
return xmat;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
String[] split = key.split(":"); String[] split = key.split(":");
if (split.length == 1) {
xmat = requestXMaterial(key, (byte) 0);
} else {
xmat = requestXMaterial(split[0], (byte) Integer.parseInt(split[1]));
}
return xmat;
}
return split.length == 1 ? requestXMaterial(key, (byte) 0):requestXMaterial(split[0], (byte) Integer.parseInt(split[1]));
}
} }
public ItemStack parseItem() { public ItemStack parseItem() {
@ -948,34 +944,21 @@ public enum MultiversionMaterials {
public boolean isDamageable(MultiversionMaterials type) { public boolean isDamageable(MultiversionMaterials type) {
String[] split = type.toString().split("_"); String[] split = type.toString().split("_");
int length = split.length;
switch (split[length - 1]) { switch (split[split.length - 1]) {
case "HELMET": case "HELMET":
return true;
case "CHESTPLATE": case "CHESTPLATE":
return true;
case "LEGGINGS": case "LEGGINGS":
return true;
case "BOOTS": case "BOOTS":
return true;
case "SWORD": case "SWORD":
return true;
case "AXE": case "AXE":
return true;
case "PICKAXE": case "PICKAXE":
return true;
case "SHOVEL": case "SHOVEL":
return true;
case "HOE": case "HOE":
return true;
case "ELYTRA": case "ELYTRA":
return true;
case "TURTLE_HELMET": case "TURTLE_HELMET":
return true;
case "TRIDENT": case "TRIDENT":
return true;
case "HORSE_ARMOR": case "HORSE_ARMOR":
return true;
case "SHEARS": case "SHEARS":
return true; return true;
default: default:
@ -985,10 +968,7 @@ public enum MultiversionMaterials {
public Material parseMaterial() { public Material parseMaterial() {
Material mat = Material.matchMaterial(this.toString()); Material mat = Material.matchMaterial(this.toString());
if (mat != null) { return mat != null ? mat:Material.matchMaterial(m);
return mat;
}
return Material.matchMaterial(m);
} }
} }

View File

@ -56,12 +56,9 @@ public class RelationUtil {
public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) { public static Relation getRelationTo(RelationParticipator me, RelationParticipator that, boolean ignorePeaceful) {
Faction fthat = getFaction(that); Faction fthat = getFaction(that);
if (fthat == null) {
return Relation.NEUTRAL; // ERROR
}
Faction fme = getFaction(me); Faction fme = getFaction(me);
if (fme == null) {
if (fthat == null || fme == null) {
return Relation.NEUTRAL; // ERROR return Relation.NEUTRAL; // ERROR
} }
@ -99,19 +96,15 @@ public class RelationUtil {
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) { public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) {
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction != null) {
if (thatFaction.isPeaceful() && thatFaction != getFaction(me)) {
return Conf.colorPeaceful;
}
if (thatFaction.isSafeZone() && thatFaction != getFaction(me)) { if (thatFaction != null && thatFaction != getFaction(me)) {
if (thatFaction.isPeaceful())
return Conf.colorPeaceful; return Conf.colorPeaceful;
} else if (thatFaction.isSafeZone())
return Conf.colorPeaceful;
if (thatFaction.isWarZone() && thatFaction != getFaction(me)) { else if (thatFaction.isWarZone())
return Conf.colorWar; return Conf.colorWar;
} }
}
return getRelationTo(that, me).getColor(); return getRelationTo(that, me).getColor();
} }

View File

@ -74,11 +74,7 @@ public abstract class MCommand<T extends MPlugin> {
} }
public String getHelpShort() { public String getHelpShort() {
if (this.helpShort == null) { return this.helpShort != null ? this.helpShort:getUsageTranslation().toString();
return getUsageTranslation().toString();
}
return this.helpShort;
} }
public void setHelpShort(String val) { public void setHelpShort(String val) {
@ -87,9 +83,8 @@ public abstract class MCommand<T extends MPlugin> {
public abstract TL getUsageTranslation(); public abstract TL getUsageTranslation();
// The commandChain is a list of the parent command chain used to get to this command. public void setCommandSender(CommandSender sender)
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) { {
// Set the execution-time specific variables
this.sender = sender; this.sender = sender;
if (sender instanceof Player) { if (sender instanceof Player) {
this.me = (Player) sender; this.me = (Player) sender;
@ -98,6 +93,12 @@ public abstract class MCommand<T extends MPlugin> {
this.me = null; this.me = null;
this.senderIsConsole = true; this.senderIsConsole = true;
} }
}
// The commandChain is a list of the parent command chain used to get to this command.
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) {
// Set the execution-time specific variables
setCommandSender(sender);
this.args = args; this.args = args;
this.commandChain = commandChain; this.commandChain = commandChain;

View File

@ -334,6 +334,6 @@ public abstract class MPlugin extends JavaPlugin {
} }
public void log(Level level, Object msg) { public void log(Level level, Object msg) {
Bukkit.getLogger().log(level, "[" + this.getDescription().getFullName() + "] " + msg); getLogger().log(level, "[" + this.getDescription().getFullName() + "] " + msg);
} }
} }

View File

@ -7,8 +7,8 @@ public enum Access {
DENY("Deny", ChatColor.DARK_RED), DENY("Deny", ChatColor.DARK_RED),
UNDEFINED("Undefined", ChatColor.GRAY); UNDEFINED("Undefined", ChatColor.GRAY);
private String name; private final String name;
private ChatColor color; private final ChatColor color;
Access(String name, ChatColor color) { Access(String name, ChatColor color) {
this.name = name; this.name = name;
@ -22,12 +22,9 @@ public enum Access {
* @return * @return
*/ */
public static Access fromString(String check) { public static Access fromString(String check) {
for (Access access : values()) { for (Access access : values())
if (access.name().equalsIgnoreCase(check)) { if (access.name().equalsIgnoreCase(check))
return access; return access;
}
}
return null; return null;
} }
@ -43,5 +40,4 @@ public enum Access {
public String toString() { public String toString() {
return name(); return name();
} }
} }

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.*;
import org.bukkit.CropState; import org.bukkit.CropState;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockGrowEvent; import org.bukkit.event.block.BlockGrowEvent;
@ -12,48 +13,44 @@ import org.bukkit.material.Crops;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class CropUpgrades implements Listener { public class CropUpgrades implements Listener {
@EventHandler @EventHandler
public void onCropGrow(BlockGrowEvent e) { public void onCropGrow(BlockGrowEvent e) {
FLocation floc = new FLocation(e.getBlock().getLocation()); FLocation floc = new FLocation(e.getBlock().getLocation());
Faction factionAtLoc = Board.getInstance().getFactionAt(floc); Faction factionAtLoc = Board.getInstance().getFactionAt(floc);
if (factionAtLoc != Factions.getInstance().getWilderness()) {
if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade("Crop"); int level = factionAtLoc.getUpgrade("Crop");
if (level != 0) { if (level != 0) {
if (level == 1) { int chance = -1;
int chance = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-1");
int randomNum = ThreadLocalRandom.current().nextInt(1, 100 + 1); switch (level)
if (randomNum <= chance) { {
growCrop(e); case 1: chance = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-1"); break;
} case 2: chance = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-2"); break;
} case 3: chance = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-3"); break;
if (level == 2) {
int chance = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-2");
int randomNum = ThreadLocalRandom.current().nextInt(1, 100 + 1);
if (randomNum <= chance) {
growCrop(e);
}
}
if (level == 3) {
int chance = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-3");
int randomNum = ThreadLocalRandom.current().nextInt(1, 100 + 1);
if (randomNum <= chance) {
growCrop(e);
}
}
}
}
} }
if (chance >= 0)
{
int randomNum = ThreadLocalRandom.current().nextInt(1, 100 + 1);
if (randomNum <= chance)
growCrop(e);
}
}
}
}
private void growCrop(BlockGrowEvent e) { private void growCrop(BlockGrowEvent e) {
if (e.getBlock().getType().equals(SavageFactions.plugin.CROPS)) { if (e.getBlock().getType().equals(SavageFactions.plugin.CROPS)) {
e.setCancelled(true); e.setCancelled(true);
Crops c = new Crops(CropState.RIPE); Crops c = new Crops(CropState.RIPE);
org.bukkit.block.BlockState bs = e.getBlock().getState(); BlockState bs = e.getBlock().getState();
bs.setData(c); bs.setData(c);
bs.update(); bs.update();
} }
Block below = e.getBlock().getLocation().subtract(0, 1, 0).getBlock(); Block below = e.getBlock().getLocation().subtract(0, 1, 0).getBlock();
if (below.getType() == SavageFactions.plugin.SUGAR_CANE_BLOCK) { if (below.getType() == SavageFactions.plugin.SUGAR_CANE_BLOCK) {
@ -64,7 +61,7 @@ public class CropUpgrades implements Listener {
} }
} }
if (below.getType() == Material.CACTUS) { else if (below.getType() == Material.CACTUS) {
Block above = e.getBlock().getLocation().add(0, 1, 0).getBlock(); Block above = e.getBlock().getLocation().add(0, 1, 0).getBlock();
if (above.getType() == Material.AIR && above.getLocation().add(0, - 2, 0).getBlock().getType() != Material.AIR) { if (above.getType() == Material.AIR && above.getLocation().add(0, - 2, 0).getBlock().getType() != Material.AIR) {

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.zcore.fupgrades; package com.massivecraft.factions.zcore.fupgrades;
import com.massivecraft.factions.*; import com.massivecraft.factions.*;
import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -9,6 +9,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
public class EXPUpgrade implements Listener { public class EXPUpgrade implements Listener {
@EventHandler @EventHandler
public void onDeath(EntityDeathEvent e) { public void onDeath(EntityDeathEvent e) {
Entity killer = e.getEntity().getKiller(); Entity killer = e.getEntity().getKiller();
@ -16,27 +17,25 @@ public class EXPUpgrade implements Listener {
if (killer == null || !(killer instanceof Player)) if (killer == null || !(killer instanceof Player))
return; return;
Location loc = e.getEntity().getLocation(); FLocation floc = new FLocation(e.getEntity().getLocation());
Faction wild = Factions.getInstance().getWilderness();
FLocation floc = new FLocation(loc);
Faction faction = Board.getInstance().getFactionAt(floc); Faction faction = Board.getInstance().getFactionAt(floc);
if (faction != wild) { if (!faction.isWilderness()) {
int level = faction.getUpgrade("Exp"); int level = faction.getUpgrade("Exp");
if (level != 0) { if (level != 0) {
if (level == 1) {
double multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-1"); double multiplier = -1;
spawnMoreExp(e, multiplier);
switch (level)
{
case 1: multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-1"); break;
case 2: multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-2"); break;
case 3: multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-3"); break;
} }
if (level == 2) {
double multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-2"); if (multiplier >= 0)
spawnMoreExp(e, multiplier); spawnMoreExp(e, multiplier);
} }
if (level == 3) {
double multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-3");
spawnMoreExp(e, multiplier);
}
}
} }
} }

View File

@ -7,6 +7,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent;
public class SpawnerUpgrades implements Listener { public class SpawnerUpgrades implements Listener {
@EventHandler @EventHandler
public void onSpawn(SpawnerSpawnEvent e) { public void onSpawn(SpawnerSpawnEvent e) {
FLocation floc = new FLocation(e.getLocation()); FLocation floc = new FLocation(e.getLocation());
@ -30,5 +31,4 @@ public class SpawnerUpgrades implements Listener {
e.getSpawner().setDelay(e.getSpawner().getDelay() - lowerby); e.getSpawner().setDelay(e.getSpawner().getDelay() - lowerby);
} }
} }

View File

@ -10,6 +10,9 @@ public class NBTCompound {
private String compundName; private String compundName;
private NBTCompound parent; private NBTCompound parent;
protected NBTCompound()
{}
protected NBTCompound(NBTCompound owner, String name) { protected NBTCompound(NBTCompound owner, String name) {
this.compundName = name; this.compundName = name;
this.parent = owner; this.parent = owner;

View File

@ -5,17 +5,14 @@ public class NBTContainer extends NBTCompound {
private Object nbt; private Object nbt;
public NBTContainer() { public NBTContainer() {
super(null, null); this(NBTReflectionUtil.getNewNBTTag());
nbt = NBTReflectionUtil.getNewNBTTag();
} }
protected NBTContainer(Object nbt) { protected NBTContainer(Object nbt) {
super(null, null);
this.nbt = nbt; this.nbt = nbt;
} }
public NBTContainer(String nbtString) throws IllegalArgumentException { public NBTContainer(String nbtString) throws IllegalArgumentException {
super(null, null);
try { try {
nbt = NBTReflectionUtil.parseNBT(nbtString); nbt = NBTReflectionUtil.parseNBT(nbtString);
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -7,7 +7,6 @@ public class NBTEntity extends NBTCompound {
private final Entity ent; private final Entity ent;
public NBTEntity(Entity entity) { public NBTEntity(Entity entity) {
super(null, null);
ent = entity; ent = entity;
} }

View File

@ -11,7 +11,6 @@ public class NBTFile extends NBTCompound {
private Object nbt; private Object nbt;
public NBTFile(File file) throws IOException { public NBTFile(File file) throws IOException {
super(null, null);
this.file = file; this.file = file;
if (file.exists()) { if (file.exists()) {
FileInputStream inputsteam = new FileInputStream(file); FileInputStream inputsteam = new FileInputStream(file);

View File

@ -7,7 +7,6 @@ public class NBTItem extends NBTCompound {
private ItemStack bukkitItem; private ItemStack bukkitItem;
public NBTItem(ItemStack item) { public NBTItem(ItemStack item) {
super(null, null);
bukkitItem = item.clone(); bukkitItem = item.clone();
} }

View File

@ -24,8 +24,7 @@ public class NBTReflectionUtil {
private static Class<?> getCraftItemStack() { private static Class<?> getCraftItemStack() {
try { try {
Class<?> clazz = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack"); return Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -35,8 +34,7 @@ public class NBTReflectionUtil {
private static Class<?> getCraftEntity() { private static Class<?> getCraftEntity() {
try { try {
Class<?> clazz = Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity"); return Class.forName("org.bukkit.craftbukkit." + version + ".entity.CraftEntity");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -46,8 +44,7 @@ public class NBTReflectionUtil {
protected static Class<?> getNBTBase() { protected static Class<?> getNBTBase() {
try { try {
Class<?> clazz = Class.forName("net.minecraft.server." + version + ".NBTBase"); return Class.forName("net.minecraft.server." + version + ".NBTBase");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -57,8 +54,7 @@ public class NBTReflectionUtil {
protected static Class<?> getNBTTagString() { protected static Class<?> getNBTTagString() {
try { try {
Class<?> clazz = Class.forName("net.minecraft.server." + version + ".NBTTagString"); return Class.forName("net.minecraft.server." + version + ".NBTTagString");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -68,8 +64,7 @@ public class NBTReflectionUtil {
protected static Class<?> getNMSItemStack() { protected static Class<?> getNMSItemStack() {
try { try {
Class<?> clazz = Class.forName("net.minecraft.server." + version + ".ItemStack"); return Class.forName("net.minecraft.server." + version + ".ItemStack");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -79,8 +74,7 @@ public class NBTReflectionUtil {
protected static Class<?> getNBTTagCompound() { protected static Class<?> getNBTTagCompound() {
try { try {
Class<?> clazz = Class.forName("net.minecraft.server." + version + ".NBTTagCompound"); return Class.forName("net.minecraft.server." + version + ".NBTTagCompound");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -90,8 +84,7 @@ public class NBTReflectionUtil {
protected static Class<?> getNBTCompressedStreamTools() { protected static Class<?> getNBTCompressedStreamTools() {
try { try {
Class<?> clazz = Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools"); return Class.forName("net.minecraft.server." + version + ".NBTCompressedStreamTools");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -101,8 +94,7 @@ public class NBTReflectionUtil {
protected static Class<?> getMojangsonParser() { protected static Class<?> getMojangsonParser() {
try { try {
Class<?> c = Class.forName("net.minecraft.server." + version + ".MojangsonParser"); return Class.forName("net.minecraft.server." + version + ".MojangsonParser");
return c;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -112,8 +104,7 @@ public class NBTReflectionUtil {
protected static Class<?> getTileEntity() { protected static Class<?> getTileEntity() {
try { try {
Class<?> clazz = Class.forName("net.minecraft.server." + version + ".TileEntity"); return Class.forName("net.minecraft.server." + version + ".TileEntity");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -123,8 +114,7 @@ public class NBTReflectionUtil {
protected static Class<?> getCraftWorld() { protected static Class<?> getCraftWorld() {
try { try {
Class<?> clazz = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld"); return Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
return clazz;
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error in ItemNBTAPI!(Outdated plugin?)"); System.out.println("Error in ItemNBTAPI!(Outdated plugin?)");
ex.printStackTrace(); ex.printStackTrace();
@ -158,8 +148,7 @@ public class NBTReflectionUtil {
public static Object setNBTTag(Object NBTTag, Object NMSItem) { public static Object setNBTTag(Object NBTTag, Object NMSItem) {
try { try {
Method method; Method method = NMSItem.getClass().getMethod("setTag", NBTTag.getClass());
method = NMSItem.getClass().getMethod("setTag", NBTTag.getClass());
method.invoke(NMSItem, NBTTag); method.invoke(NMSItem, NBTTag);
return NMSItem; return NMSItem;
} catch (Exception ex) { } catch (Exception ex) {
@ -170,11 +159,10 @@ public class NBTReflectionUtil {
public static Object getNMSItemStack(ItemStack item) { public static Object getNMSItemStack(ItemStack item) {
Class<?> clazz = getCraftItemStack(); Class<?> clazz = getCraftItemStack();
Method method;
try { try {
method = clazz.getMethod("asNMSCopy", ItemStack.class); Method method = clazz.getMethod("asNMSCopy", ItemStack.class);
Object answer = method.invoke(clazz, item); return method.invoke(clazz, item);
return answer;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -183,9 +171,9 @@ public class NBTReflectionUtil {
public static Object getNMSEntity(Entity entity) { public static Object getNMSEntity(Entity entity) {
Class<?> clazz = getCraftEntity(); Class<?> clazz = getCraftEntity();
Method method;
try { try {
method = clazz.getMethod("getHandle"); Method method = clazz.getMethod("getHandle");
return method.invoke(getCraftEntity().cast(entity)); return method.invoke(getCraftEntity().cast(entity));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -195,9 +183,9 @@ public class NBTReflectionUtil {
public static Object parseNBT(String json) { public static Object parseNBT(String json) {
Class<?> cis = getMojangsonParser(); Class<?> cis = getMojangsonParser();
Method method;
try { try {
method = cis.getMethod("parse", String.class); Method method = cis.getMethod("parse", String.class);
return method.invoke(null, json); return method.invoke(null, json);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -207,9 +195,9 @@ public class NBTReflectionUtil {
public static Object readNBTFile(FileInputStream stream) { public static Object readNBTFile(FileInputStream stream) {
Class<?> clazz = getNBTCompressedStreamTools(); Class<?> clazz = getNBTCompressedStreamTools();
Method method;
try { try {
method = clazz.getMethod("a", InputStream.class); Method method = clazz.getMethod("a", InputStream.class);
return method.invoke(clazz, stream); return method.invoke(clazz, stream);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -219,9 +207,9 @@ public class NBTReflectionUtil {
public static Object saveNBTFile(Object nbt, FileOutputStream stream) { public static Object saveNBTFile(Object nbt, FileOutputStream stream) {
Class<?> clazz = getNBTCompressedStreamTools(); Class<?> clazz = getNBTCompressedStreamTools();
Method method;
try { try {
method = clazz.getMethod("a", getNBTTagCompound(), OutputStream.class); Method method = clazz.getMethod("a", getNBTTagCompound(), OutputStream.class);
return method.invoke(clazz, nbt, stream); return method.invoke(clazz, nbt, stream);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -231,11 +219,10 @@ public class NBTReflectionUtil {
public static ItemStack getBukkitItemStack(Object item) { public static ItemStack getBukkitItemStack(Object item) {
Class<?> clazz = getCraftItemStack(); Class<?> clazz = getCraftItemStack();
Method method;
try { try {
method = clazz.getMethod("asCraftMirror", item.getClass()); Method method = clazz.getMethod("asCraftMirror", item.getClass());
Object answer = method.invoke(clazz, item); return (ItemStack) method.invoke(clazz, item);
return (ItemStack) answer;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -244,11 +231,10 @@ public class NBTReflectionUtil {
public static Object getItemRootNBTTagCompound(Object nmsitem) { public static Object getItemRootNBTTagCompound(Object nmsitem) {
Class<?> clazz = nmsitem.getClass(); Class<?> clazz = nmsitem.getClass();
Method method;
try { try {
method = clazz.getMethod("getTag"); Method method = clazz.getMethod("getTag");
Object answer = method.invoke(nmsitem); return method.invoke(nmsitem);
return answer;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -258,8 +244,7 @@ public class NBTReflectionUtil {
public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) { public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) {
Class<?> clazz = getNMSItemStack(); Class<?> clazz = getNMSItemStack();
try { try {
Object nmsstack = clazz.getConstructor(getNBTTagCompound()).newInstance(gettoCompount(nbtcompound.getCompound(), nbtcompound)); return clazz.getConstructor(getNBTTagCompound()).newInstance(gettoCompount(nbtcompound.getCompound(), nbtcompound));
return nmsstack;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -268,9 +253,9 @@ public class NBTReflectionUtil {
public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) { public static NBTContainer convertNMSItemtoNBTCompound(Object nmsitem) {
Class<?> clazz = nmsitem.getClass(); Class<?> clazz = nmsitem.getClass();
Method method;
try { try {
method = clazz.getMethod("save", getNBTTagCompound()); Method method = clazz.getMethod("save", getNBTTagCompound());
Object answer = method.invoke(nmsitem, getNewNBTTag()); Object answer = method.invoke(nmsitem, getNewNBTTag());
return new NBTContainer(answer); return new NBTContainer(answer);
} catch (Exception e) { } catch (Exception e) {
@ -281,14 +266,12 @@ public class NBTReflectionUtil {
public static Object getEntityNBTTagCompound(Object nmsitem) { public static Object getEntityNBTTagCompound(Object nmsitem) {
Class<?> c = nmsitem.getClass(); Class<?> c = nmsitem.getClass();
Method method;
try { try {
method = c.getMethod(MethodNames.getEntityNbtGetterMethodName(), getNBTTagCompound()); Method method = c.getMethod(MethodNames.getEntityNbtGetterMethodName(), getNBTTagCompound());
Object nbt = getNBTTagCompound().newInstance(); Object nbt = getNBTTagCompound().newInstance();
Object answer = method.invoke(nmsitem, nbt); Object answer = method.invoke(nmsitem, nbt);
if (answer == null) return answer != null ? answer:nbt;
answer = nbt;
return answer;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -308,18 +291,16 @@ public class NBTReflectionUtil {
} }
public static Object getTileEntityNBTTagCompound(BlockState tile) { public static Object getTileEntityNBTTagCompound(BlockState tile) {
Method method;
try { try {
Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ()); Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ());
Object cworld = getCraftWorld().cast(tile.getWorld()); Object cworld = getCraftWorld().cast(tile.getWorld());
Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld); Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld);
Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos); Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos);
method = getTileEntity().getMethod(MethodNames.getTileDataMethodName(), getNBTTagCompound()); Method method = getTileEntity().getMethod(MethodNames.getTileDataMethodName(), getNBTTagCompound());
Object tag = getNBTTagCompound().newInstance(); Object tag = getNBTTagCompound().newInstance();
Object answer = method.invoke(o, tag); Object answer = method.invoke(o, tag);
if (answer == null)
answer = tag; return answer != null ? answer:tag;
return answer;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -327,13 +308,12 @@ public class NBTReflectionUtil {
} }
public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) { public static void setTileEntityNBTTagCompound(BlockState tile, Object comp) {
Method method;
try { try {
Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ()); Object pos = getNewBlockPosition(tile.getX(), tile.getY(), tile.getZ());
Object cworld = getCraftWorld().cast(tile.getWorld()); Object cworld = getCraftWorld().cast(tile.getWorld());
Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld); Object nmsworld = cworld.getClass().getMethod("getHandle").invoke(cworld);
Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos); Object o = nmsworld.getClass().getMethod("getTileEntity", pos.getClass()).invoke(nmsworld, pos);
method = getTileEntity().getMethod("a", getNBTTagCompound()); Method method = getTileEntity().getMethod("a", getNBTTagCompound());
method.invoke(o, comp); method.invoke(o, comp);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -342,11 +322,10 @@ public class NBTReflectionUtil {
public static Object getSubNBTTagCompound(Object compound, String name) { public static Object getSubNBTTagCompound(Object compound, String name) {
Class<?> c = compound.getClass(); Class<?> c = compound.getClass();
Method method;
try { try {
method = c.getMethod("getCompound", String.class); Method method = c.getMethod("getCompound", String.class);
Object answer = method.invoke(compound, name); return method.invoke(compound, name);
return answer;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -364,9 +343,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(nbttag, comp); Object workingtag = gettoCompount(nbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("set", String.class, getNBTBase()); Method method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
method.invoke(workingtag, name, getNBTTagCompound().newInstance()); method.invoke(workingtag, name, getNBTTagCompound().newInstance());
comp.setCompound(nbttag); comp.setCompound(nbttag);
return; return;
@ -381,7 +360,7 @@ public class NBTReflectionUtil {
if (root == null) { if (root == null) {
root = getNewNBTTag(); root = getNewNBTTag();
} }
return (gettoCompount(root, comp)) != null; return gettoCompount(root, comp) != null;
} }
public static Object gettoCompount(Object nbttag, NBTCompound comp) { public static Object gettoCompount(Object nbttag, NBTCompound comp) {
@ -406,9 +385,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("a", getNBTTagCompound()); Method method = workingtag.getClass().getMethod("a", getNBTTagCompound());
method.invoke(workingtag, nbtcompound.getCompound()); method.invoke(workingtag, nbtcompound.getCompound());
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -427,9 +406,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setString", String.class, String.class); Method method = workingtag.getClass().getMethod("setString", String.class, String.class);
method.invoke(workingtag, key, text); method.invoke(workingtag, key, text);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -444,9 +423,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getString", String.class); Method method = workingtag.getClass().getMethod("getString", String.class);
return (String) method.invoke(workingtag, key); return (String) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -461,9 +440,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("get", String.class); Method method = workingtag.getClass().getMethod("get", String.class);
return method.invoke(workingtag, key).toString(); return method.invoke(workingtag, key).toString();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -482,9 +461,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setInt", String.class, int.class); Method method = workingtag.getClass().getMethod("setInt", String.class, int.class);
method.invoke(workingtag, key, i); method.invoke(workingtag, key, i);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -499,9 +478,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getInt", String.class); Method method = workingtag.getClass().getMethod("getInt", String.class);
return (Integer) method.invoke(workingtag, key); return (Integer) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -520,9 +499,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setByteArray", String.class, byte[].class); Method method = workingtag.getClass().getMethod("setByteArray", String.class, byte[].class);
method.invoke(workingtag, key, b); method.invoke(workingtag, key, b);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -538,9 +517,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getByteArray", String.class); Method method = workingtag.getClass().getMethod("getByteArray", String.class);
return (byte[]) method.invoke(workingtag, key); return (byte[]) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -559,9 +538,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setIntArray", String.class, int[].class); Method method = workingtag.getClass().getMethod("setIntArray", String.class, int[].class);
method.invoke(workingtag, key, i); method.invoke(workingtag, key, i);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -576,9 +555,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getIntArray", String.class); Method method = workingtag.getClass().getMethod("getIntArray", String.class);
return (int[]) method.invoke(workingtag, key); return (int[]) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -597,9 +576,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setFloat", String.class, float.class); Method method = workingtag.getClass().getMethod("setFloat", String.class, float.class);
method.invoke(workingtag, key, f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -614,9 +593,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getFloat", String.class); Method method = workingtag.getClass().getMethod("getFloat", String.class);
return (Float) method.invoke(workingtag, key); return (Float) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -635,9 +614,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setLong", String.class, long.class); Method method = workingtag.getClass().getMethod("setLong", String.class, long.class);
method.invoke(workingtag, key, f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -652,9 +631,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getLong", String.class); Method method = workingtag.getClass().getMethod("getLong", String.class);
return (Long) method.invoke(workingtag, key); return (Long) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -673,9 +652,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setShort", String.class, short.class); Method method = workingtag.getClass().getMethod("setShort", String.class, short.class);
method.invoke(workingtag, key, f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -690,9 +669,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getShort", String.class); Method method = workingtag.getClass().getMethod("getShort", String.class);
return (Short) method.invoke(workingtag, key); return (Short) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -711,9 +690,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setByte", String.class, byte.class); Method method = workingtag.getClass().getMethod("setByte", String.class, byte.class);
method.invoke(workingtag, key, f); method.invoke(workingtag, key, f);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -728,9 +707,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getByte", String.class); Method method = workingtag.getClass().getMethod("getByte", String.class);
return (Byte) method.invoke(workingtag, key); return (Byte) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -749,9 +728,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setDouble", String.class, double.class); Method method = workingtag.getClass().getMethod("setDouble", String.class, double.class);
method.invoke(workingtag, key, d); method.invoke(workingtag, key, d);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -766,9 +745,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getDouble", String.class); Method method = workingtag.getClass().getMethod("getDouble", String.class);
return (Double) method.invoke(workingtag, key); return (Double) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -783,9 +762,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return 0; if (!valideCompound(comp)) return 0;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod(MethodNames.getTypeMethodName(), String.class); Method method = workingtag.getClass().getMethod(MethodNames.getTypeMethodName(), String.class);
return (byte) method.invoke(workingtag, key); return (byte) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -804,9 +783,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("setBoolean", String.class, boolean.class); Method method = workingtag.getClass().getMethod("setBoolean", String.class, boolean.class);
method.invoke(workingtag, key, d); method.invoke(workingtag, key, d);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -821,9 +800,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getBoolean", String.class); Method method = workingtag.getClass().getMethod("getBoolean", String.class);
return (Boolean) method.invoke(workingtag, key); return (Boolean) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -845,9 +824,8 @@ public class NBTReflectionUtil {
return; return;
} }
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("set", String.class, getNBTBase()); Method method = workingtag.getClass().getMethod("set", String.class, getNBTBase());
method.invoke(workingtag, key, val); method.invoke(workingtag, key, val);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -862,9 +840,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("getList", String.class, int.class); Method method = workingtag.getClass().getMethod("getList", String.class, int.class);
return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId())); return new NBTList(comp, key, type, method.invoke(workingtag, key, type.getId()));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -885,10 +863,8 @@ public class NBTReflectionUtil {
public static <T> T getObject(NBTCompound comp, String key, Class<T> type) { public static <T> T getObject(NBTCompound comp, String key, Class<T> type) {
if (!MinecraftVersion.hasGsonSupport()) return null; if (!MinecraftVersion.hasGsonSupport()) return null;
String json = getString(comp, key); String json = getString(comp, key);
if (json == null) {
return null; return json != null ? GsonWrapper.deserializeJson(json, type):null;
}
return GsonWrapper.deserializeJson(json, type);
} }
public static void remove(NBTCompound comp, String key) { public static void remove(NBTCompound comp, String key) {
@ -898,9 +874,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return; if (!valideCompound(comp)) return;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("remove", String.class); Method method = workingtag.getClass().getMethod("remove", String.class);
method.invoke(workingtag, key); method.invoke(workingtag, key);
comp.setCompound(rootnbttag); comp.setCompound(rootnbttag);
} catch (Exception ex) { } catch (Exception ex) {
@ -915,9 +891,9 @@ public class NBTReflectionUtil {
} }
if (!valideCompound(comp)) return null; if (!valideCompound(comp)) return null;
Object workingtag = gettoCompount(rootnbttag, comp); Object workingtag = gettoCompount(rootnbttag, comp);
Method method;
try { try {
method = workingtag.getClass().getMethod("hasKey", String.class); Method method = workingtag.getClass().getMethod("hasKey", String.class);
return (Boolean) method.invoke(workingtag, key); return (Boolean) method.invoke(workingtag, key);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();

View File

@ -7,7 +7,6 @@ public class NBTTileEntity extends NBTCompound {
private final BlockState tile; private final BlockState tile;
public NBTTileEntity(BlockState tile) { public NBTTileEntity(BlockState tile) {
super(null, null);
this.tile = tile; this.tile = tile;
} }

View File

@ -5,17 +5,11 @@ public class MethodNames {
private final static MinecraftVersion MINECRAFT_VERSION = MinecraftVersion.getVersion(); private final static MinecraftVersion MINECRAFT_VERSION = MinecraftVersion.getVersion();
public static String getTileDataMethodName() { public static String getTileDataMethodName() {
if (MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3) { return MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3 ? "b":"save";
return "b";
}
return "save";
} }
public static String getTypeMethodName() { public static String getTypeMethodName() {
if (MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3) { return MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3 ? "b":"d";
return "b";
}
return "d";
} }
public static String getEntityNbtGetterMethodName() { public static String getEntityNbtGetterMethodName() {
@ -27,10 +21,6 @@ public class MethodNames {
} }
public static String getRemoveMethodName() { public static String getRemoveMethodName() {
if (MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3) { return MINECRAFT_VERSION == MinecraftVersion.MC1_8_R3 ? "a":"remove";
return "a";
} }
return "remove";
}
} }

View File

@ -22,34 +22,35 @@ public enum MinecraftVersion {
} }
public static MinecraftVersion getVersion() { public static MinecraftVersion getVersion() {
if (version != null) { if (version == null)
return version; {
}
final String ver = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; final String ver = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
System.out.println("[NBTAPI] Found Spigot: " + ver + "!Trying to find NMS support"); System.out.println("[NBTAPI] Found Spigot: " + ver + "!Trying to find NMS support");
try { try {
version = MinecraftVersion.valueOf(ver.replace("v", "MC")); version = MinecraftVersion.valueOf(ver.replace("v", "MC"));
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
version = MinecraftVersion.Unknown; version = MinecraftVersion.Unknown;
} }
if (version != Unknown) { if (version != Unknown) {
System.out.println("[NBTAPI] NMS support '" + version.name() + "' loaded!"); System.out.println("[NBTAPI] NMS support '" + version.name() + "' loaded!");
} else { } else {
System.out.println("[NBTAPI] Wasn't able to find NMS Support!Some functions will not work!"); System.out.println("[NBTAPI] Wasn't able to find NMS Support!Some functions will not work!");
} }
}
return version; return version;
} }
public static boolean hasGsonSupport() { public static boolean hasGsonSupport() {
if (hasGsonSupport != null) { if (hasGsonSupport == null) {
return hasGsonSupport;
}
try { try {
System.out.println("Found Gson: " + Class.forName("com.google.gson.Gson")); System.out.println("Found Gson: " + Class.forName("com.google.gson.Gson"));
hasGsonSupport = true; hasGsonSupport = true;
} catch (Exception ex) { } catch (Exception ex) {
hasGsonSupport = false; hasGsonSupport = false;
} }
}
return hasGsonSupport; return hasGsonSupport;
} }

View File

@ -4,8 +4,10 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.cmd.CmdFly; import com.massivecraft.factions.cmd.CmdFly;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FPlayerStoppedFlying; import com.massivecraft.factions.event.FPlayerStoppedFlying;
import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.event.LandClaimEvent; import com.massivecraft.factions.event.LandClaimEvent;
import com.massivecraft.factions.event.PowerRegenEvent; import com.massivecraft.factions.event.PowerRegenEvent;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
@ -547,6 +549,7 @@ public abstract class MemoryFPlayer implements FPlayer {
} else if (hasFaction() && getFaction().isPowerFrozen()) { } else if (hasFaction() && getFaction().isPowerFrozen()) {
return; // Don't let power regen if faction power is frozen. return; // Don't let power regen if faction power is frozen.
} }
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime; long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now; this.lastPowerUpdateTime = now;
@ -560,10 +563,7 @@ public abstract class MemoryFPlayer implements FPlayer {
Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent); Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent);
if (!powerRegenEvent.isCancelled()) if (!powerRegenEvent.isCancelled())
{ this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000
int millisPerMinute = 60 * 1000;
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
}
} }
public void losePowerFromBeingOffline() { public void losePowerFromBeingOffline() {
@ -712,6 +712,9 @@ public abstract class MemoryFPlayer implements FPlayer {
fplayer.msg(TL.LEAVE_DISBANDED, myFaction.describeTo(fplayer, true)); fplayer.msg(TL.LEAVE_DISBANDED, myFaction.describeTo(fplayer, true));
} }
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(null, getId(), PlayerDisbandReason.LEAVE);
Bukkit.getPluginManager().callEvent(disbandEvent);
Factions.getInstance().removeFaction(myFaction.getId()); Factions.getInstance().removeFaction(myFaction.getId());
if (Conf.logFactionDisband) { if (Conf.logFactionDisband) {
SavageFactions.plugin.log(TL.LEAVE_DISBANDEDLOG.format(myFaction.getTag(), myFaction.getId(), this.getName())); SavageFactions.plugin.log(TL.LEAVE_DISBANDEDLOG.format(myFaction.getTag(), myFaction.getId(), this.getName()));
@ -1124,17 +1127,13 @@ public abstract class MemoryFPlayer implements FPlayer {
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it // notifyFailure is false if called by auto-claim; no need to notify on every failure for it
// return value is false on failure, true on success // return value is false on failure, true on success
Faction currentFaction = Board.getInstance().getFactionAt(flocation); Faction currentFaction = Board.getInstance().getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded(); int ownedLand = forFaction.getLandRounded();
if (!this.canClaimForFactionAtLocation(forFaction, flocation, notifyFailure)) { if (!this.canClaimForFactionAtLocation(forFaction, flocation, notifyFailure)) {
return false; return false;
} }
// if economy is enabled and they're not on the bypass list, make sure they can pay // if economy is enabled and they're not on the bypass list, make sure they can pay
boolean mustPay = Econ.shouldBeUsed() && !this.isAdminBypassing() && !forFaction.isSafeZone() && !forFaction.isWarZone(); boolean mustPay = Econ.shouldBeUsed() && !this.isAdminBypassing() && !forFaction.isSafeZone() && !forFaction.isWarZone();
double cost = 0.0; double cost = 0.0;
@ -1159,7 +1158,7 @@ public abstract class MemoryFPlayer implements FPlayer {
} }
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this); LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this);
Bukkit.getServer().getPluginManager().callEvent(claimEvent); Bukkit.getPluginManager().callEvent(claimEvent);
if (claimEvent.isCancelled()) { if (claimEvent.isCancelled()) {
return false; return false;
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.zcore.persist;
import com.massivecraft.factions.*; import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FactionDisbandEvent; import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
@ -236,13 +237,18 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
} }
} }
@Override
public void disband(Player disbander) { public void disband(Player disbander) {
disband(disbander, PlayerDisbandReason.PLUGIN);
}
@Override
public void disband(Player disbander, PlayerDisbandReason reason) {
boolean disbanderIsConsole = disbander == null; boolean disbanderIsConsole = disbander == null;
FPlayer fdisbander = FPlayers.getInstance().getByOfflinePlayer(disbander); FPlayer fdisbander = FPlayers.getInstance().getByOfflinePlayer(disbander);
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(disbander, this.getId()); FactionDisbandEvent disbandEvent = new FactionDisbandEvent(disbander, this.getId(), reason);
Bukkit.getServer().getPluginManager().callEvent(disbandEvent); Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
if (disbandEvent.isCancelled()) { if (disbandEvent.isCancelled()) {
return; return;
@ -982,7 +988,13 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
// used when current leader is about to be removed from the faction; // used when current leader is about to be removed from the faction;
// promotes new leader, or disbands faction if no other members left // promotes new leader, or disbands faction if no other members left
@Override
public void promoteNewLeader() { public void promoteNewLeader() {
promoteNewLeader(false);
}
@Override
public void promoteNewLeader(boolean autoLeave) {
if (!this.isNormal()) { if (!this.isNormal()) {
return; return;
} }
@ -1008,13 +1020,16 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
// no members left and faction isn't permanent, so disband it // no members left and faction isn't permanent, so disband it
if (Conf.logFactionDisband) { if (Conf.logFactionDisband) {
SavageFactions.plugin.log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left."); SavageFactions.plugin.log("The faction " + this.getTag() + " (" + this.getId() + ") has been disbanded since it has no members left" + (autoLeave ? " and by inactivity":"")+ ".");
} }
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
fplayer.msg("The faction %s<i> was disbanded.", this.getTag(fplayer)); fplayer.msg("The faction %s<i> was disbanded.", this.getTag(fplayer));
} }
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(null, getId(), autoLeave ? PlayerDisbandReason.INACTIVITY:PlayerDisbandReason.LEAVE);
Bukkit.getPluginManager().callEvent(disbandEvent);
Factions.getInstance().removeFaction(getId()); Factions.getInstance().removeFaction(getId());
} else { // promote new faction admin } else { // promote new faction admin
if (oldLeader != null) { if (oldLeader != null) {

View File

@ -2,14 +2,12 @@ package com.massivecraft.factions.zcore.util;
import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.MPlugin;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class PermUtil { public class PermUtil {
public Map<String, String> permissionDescriptions = new HashMap<>(); public Map<String, String> permissionDescriptions = new HashMap<>();
@ -37,25 +35,15 @@ public class PermUtil {
public String getPermissionDescription(String perm) { public String getPermissionDescription(String perm) {
String desc = permissionDescriptions.get(perm); String desc = permissionDescriptions.get(perm);
if (desc == null) {
return TL.GENERIC_DOTHAT.toString(); return desc != null ? desc:TL.GENERIC_DOTHAT.toString();
}
return desc;
} }
/** /**
* This method tests if me has a certain permission and returns true if me has. Otherwise false * This method tests if me has a certain permission and returns true if me has. Otherwise false
*/ */
public boolean has(CommandSender me, String perm) { public boolean has(CommandSender me, String perm) {
if (me == null) { return me != null ? me.hasPermission(perm):false;
return false;
}
if (!(me instanceof Player)) {
return me.hasPermission(perm);
}
return me.hasPermission(perm);
} }
public boolean has(CommandSender me, String perm, boolean informSenderIfNot) { public boolean has(CommandSender me, String perm, boolean informSenderIfNot) {

View File

@ -106,7 +106,6 @@ public enum TL {
COMMAND_UPGRADES_DESCRIPTION("&cOpen the Upgrades Menu"), COMMAND_UPGRADES_DESCRIPTION("&cOpen the Upgrades Menu"),
COMMAND_ADMIN_NOTMEMBER("&c&l[!] &7%1$s &cis not a member in your faction."), COMMAND_ADMIN_NOTMEMBER("&c&l[!] &7%1$s &cis not a member in your faction."),
COMMAND_ADMIN_NOTADMIN("&c&l[!] &cYou are not the faction admin."), COMMAND_ADMIN_NOTADMIN("&c&l[!] &cYou are not the faction admin."),
COMMAND_ADMIN_TARGETSELF("'&c&l[!] &cThe target player musn''t be yourself."), COMMAND_ADMIN_TARGETSELF("'&c&l[!] &cThe target player musn''t be yourself."),
@ -495,7 +494,7 @@ public enum TL {
COMMAND_PERM_SET("&c&l[!]&7 Set permission&c %1$s &7to &c%2$s &7for relation&c %3$s"), COMMAND_PERM_SET("&c&l[!]&7 Set permission&c %1$s &7to &c%2$s &7for relation&c %3$s"),
COMMAND_PERM_TOP("RCT MEM OFF ALLY TRUCE NEUT ENEMY"), COMMAND_PERM_TOP("RCT MEM OFF ALLY TRUCE NEUT ENEMY"),
COMMAND_PERMANENT_DESCRIPTION("Toggles a faction's permanence"), //TODO: Real word? COMMAND_PERMANENT_DESCRIPTION("Toggles a permanent faction option"),
COMMAND_PERMANENT_GRANT("&c&l[!]&7 added permanent status to"), COMMAND_PERMANENT_GRANT("&c&l[!]&7 added permanent status to"),
COMMAND_PERMANENT_REVOKE("&c&l[!]&7 removed permanent status from"), COMMAND_PERMANENT_REVOKE("&c&l[!]&7 removed permanent status from"),
COMMAND_PERMANENT_YOURS("&c&l[!]&7 &c%1$s&7 has &c%2$s&7 your faction"), COMMAND_PERMANENT_YOURS("&c&l[!]&7 &c%1$s&7 has &c%2$s&7 your faction"),
@ -506,7 +505,7 @@ public enum TL {
COMMAND_PROMOTE_DEMOTED("demoted"), COMMAND_PROMOTE_DEMOTED("demoted"),
COMMAND_PROMOTE_COLEADER_ADMIN("&c&l[!]&7 &cColeaders cant promote players to Admin!"), COMMAND_PROMOTE_COLEADER_ADMIN("&c&l[!]&7 &cColeaders cant promote players to Admin!"),
COMMAND_PERMANENTPOWER_DESCRIPTION("Toggle faction power permanence"), //TODO: This a real word? COMMAND_PERMANENTPOWER_DESCRIPTION("Toggle permanent faction power option"),
COMMAND_PERMANENTPOWER_GRANT("added permanentpower status to"), COMMAND_PERMANENTPOWER_GRANT("added permanentpower status to"),
COMMAND_PERMANENTPOWER_REVOKE("removed permanentpower status from"), COMMAND_PERMANENTPOWER_REVOKE("removed permanentpower status from"),
COMMAND_PERMANENTPOWER_SUCCESS("&c&l[!]&7 You&c %s &7%s."), COMMAND_PERMANENTPOWER_SUCCESS("&c&l[!]&7 You&c %s &7%s."),
@ -745,7 +744,6 @@ public enum TL {
COMMAND_WARUNCLAIMALL_SUCCESS("<i>You unclaimed ALL war zone land."), COMMAND_WARUNCLAIMALL_SUCCESS("<i>You unclaimed ALL war zone land."),
COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."), COMMAND_WARUNCLAIMALL_LOG("%1$s unclaimed all war zones."),
COMMAND_RULES_DISABLED_MSG("&cThis command is disabled!"), COMMAND_RULES_DISABLED_MSG("&cThis command is disabled!"),
COMMAND_RULES_DESCRIPTION("set/remove/add rules!"), COMMAND_RULES_DESCRIPTION("set/remove/add rules!"),
COMMAND_RULES_ADD_INVALIDARGS("Please include a rule!"), COMMAND_RULES_ADD_INVALIDARGS("Please include a rule!"),
@ -756,7 +754,6 @@ public enum TL {
COMMAND_RULES_SET_SUCCESS("&cRule set successfully!"), COMMAND_RULES_SET_SUCCESS("&cRule set successfully!"),
COMMAND_RULES_CLEAR_SUCCESS("&cRule cleared successfully!"), COMMAND_RULES_CLEAR_SUCCESS("&cRule cleared successfully!"),
/** /**
* Leaving - This is accessed through a command, and so it MAY need a COMMAND_* slug :s * Leaving - This is accessed through a command, and so it MAY need a COMMAND_* slug :s
*/ */
@ -843,6 +840,7 @@ public enum TL {
WARBANNER_NOFACTION("&cYou need a faction to use a warbanner!"), WARBANNER_NOFACTION("&cYou need a faction to use a warbanner!"),
WARBANNER_COOLDOWN("&cThe warbanner is on cooldown for your faction!"), WARBANNER_COOLDOWN("&cThe warbanner is on cooldown for your faction!"),
WARBANNER_INVALIDLOC("&cYou can only use warbanners in enemy land or the warzone"), WARBANNER_INVALIDLOC("&cYou can only use warbanners in enemy land or the warzone"),
/** /**
* ASCII compass (for chat map) * ASCII compass (for chat map)
*/ */
@ -1014,7 +1012,7 @@ public enum TL {
@Override @Override
public String toString() { public String toString() {
return this == TITLE ? ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)) + " " : ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)); return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def)) + (this == TITLE ? " ":"");
} }
public String format(Object... args) { public String format(Object... args) {

View File

@ -119,13 +119,10 @@ public class TextUtil {
public static String implode(List<String> list, String glue) { public static String implode(List<String> list, String glue) {
StringBuilder ret = new StringBuilder(); StringBuilder ret = new StringBuilder();
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++)
if (i != 0) { ret.append(glue).append(list.get(i));
ret.append(glue);
} return ret.length() > 0 ? ret.toString().substring(glue.length()):"";
ret.append(list.get(i));
}
return ret.toString();
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -133,11 +130,7 @@ public class TextUtil {
// -------------------------------------------- // // -------------------------------------------- //
public static String repeat(String s, int times) { public static String repeat(String s, int times) {
if (times <= 0) { return times > 0 ? s + repeat(s, times - 1):"";
return "";
} else {
return s + repeat(s, times - 1);
}
} }
public static String getMaterialName(Material material) { public static String getMaterialName(Material material) {