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("tpa");
territoryProtectedMaterials.add(SavageFactions.plugin.WOODEN_DOOR);
territoryProtectedMaterials.add(SavageFactions.plugin.TRAP_DOOR);
territoryProtectedMaterials.add(SavageFactions.plugin.FENCE_GATE);
@ -443,7 +442,7 @@ public class Conf {
public enum Backend {
JSON,
//MYSQL, TODO
//MYSQL, TODO add MySQL storage
;
}
}

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.struct.BanInfo;
@ -203,6 +204,8 @@ public interface Faction extends EconomyParticipator {
void resetPerms();
void disband(Player disbander);
void disband(Player disbander, PlayerDisbandReason reason);
// -------------------------------
// Relation and relation colors
@ -282,6 +285,8 @@ public interface Faction extends EconomyParticipator {
// used when current leader is about to be removed from the faction;
// promotes new leader, or disbands faction if no other members left
void promoteNewLeader();
void promoteNewLeader(boolean autoLeave);
Role getDefaultRole();

View File

@ -12,6 +12,8 @@ import com.massivecraft.factions.listeners.*;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.util.*;
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.fperms.Access;
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.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -42,6 +45,7 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class SavageFactions extends MPlugin {
@ -74,6 +78,8 @@ public class SavageFactions extends MPlugin {
private ClipPlaceholderAPIManager clipPlaceholderAPIManager;
private boolean mvdwPlaceholderAPIManager = false;
private Listener[] eventsListener;
public SavageFactions() {
plugin = this;
}
@ -117,18 +123,10 @@ public class SavageFactions extends MPlugin {
// Vault dependency check.
if (SavageFactions.plugin.getServer().getPluginManager().getPlugin("Vault") == null) {
SavageFactions.plugin.log("Vault is not present, the plugin will not run properly.");
this.onDisable();
Bukkit.getScheduler().scheduleSyncDelayedTask(this,
new Runnable() {
@Override
public void run() {
SavageFactions.plugin.getServer().getPluginManager().disablePlugin(SavageFactions.plugin);
}
}, 20L);
if (getServer().getPluginManager().getPlugin("Vault") == null) {
log("Vault is not present, the plugin will not run properly.");
getServer().getPluginManager().disablePlugin(plugin);
return;
}
int version = Integer.parseInt(ReflectionUtils.PackageType.getServerVersion().split("_")[1]);
@ -144,7 +142,7 @@ public class SavageFactions extends MPlugin {
changeItemIDSInConfig();
}
setupMultiversionMaterials();
migrateFPlayerLeaders();
migrateFPlayerLeaders();
log("==== End Setup ====");
if (!preEnable()) {
@ -154,13 +152,13 @@ public class SavageFactions extends MPlugin {
saveDefaultConfig();
// Load Conf from disk
Conf.load();
Essentials.setup();
hookedPlayervaults = setupPlayervaults();
FPlayers.getInstance().load();
Factions.getInstance().load();
for (FPlayer fPlayer : FPlayers.getInstance().getAllFPlayers()) {
Faction faction = Factions.getInstance().getFactionById(fPlayer.getFactionId());
if (faction == null) {
@ -170,10 +168,10 @@ public class SavageFactions extends MPlugin {
}
faction.addFPlayer(fPlayer);
}
Board.getInstance().load();
Board.getInstance().clean();
// Add Base Commands
this.cmdBase = new FCmdRoot();
this.cmdAutoHelp = new CmdAutoHelp();
@ -196,32 +194,37 @@ public class SavageFactions extends MPlugin {
new MassiveStats(this);
}
if (version > 8) {
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;
}
// Register Event Handlers
getServer().getPluginManager().registerEvents(new FactionsPlayerListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsChatListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsEntityListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsExploitListener(), this);
getServer().getPluginManager().registerEvents(new FactionsBlockListener(this), this);
getServer().getPluginManager().registerEvents(new FUpgradesGUI(), this);
getServer().getPluginManager().registerEvents(new EXPUpgrade(), this);
getServer().getPluginManager().registerEvents(new CropUpgrades(), this);
getServer().getPluginManager().registerEvents(new SpawnerUpgrades(), this);
eventsListener = new Listener[] {
new FactionsPlayerListener(this),
new FactionsChatListener(this),
new FactionsEntityListener(this),
new FactionsExploitListener(),
new FactionsBlockListener(this),
new FUpgradesGUI(),
new EXPUpgrade(),
new CropUpgrades(),
new SpawnerUpgrades(),
};
for (Listener eventListener: eventsListener)
getServer().getPluginManager().registerEvents(eventListener, this);
// since some other plugins execute commands directly through this command interface, provide it
this.getCommand(this.refCommand).setExecutor(this);
getCommand(this.refCommand).setExecutor(this);
getCommand(this.refCommand).setTabCompleter(this);
if (SavageFactions.plugin.getDescription().getFullName().contains("BETA")) {
if (getDescription().getFullName().contains("BETA")) {
divider();
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!");
@ -229,7 +232,6 @@ public class SavageFactions extends MPlugin {
divider();
}
this.setupPlaceholderAPI();
this.postEnable();
this.loadSuccessful = true;
@ -311,8 +313,9 @@ public class SavageFactions extends MPlugin {
}
private void migrateFPlayerLeaders() {
List<String> lines = new ArrayList<String>();
List<String> lines = new ArrayList<>();
File fplayerFile = new File("plugins\\Factions\\players.json");
try {
BufferedReader br = new BufferedReader(new FileReader(fplayerFile));
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"
+ " there is no need to migrate old players.json file.");
}
}
private void changeItemIDSInConfig() {
SavageFactions.plugin.log("Starting conversion of legacy material in config to 1.13 materials.");
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.normal", "GOLD_SWORD", "GOLDEN_SWORD");
replaceStringInConfig("fperm-gui.relation.materials.ally", "GOLD_AXE", "GOLDEN_AXE");
replaceStringInConfig("fperm-gui.relation.materials.neutral", "WOOD_AXE", "WOODEN_AXE");
ConfigurationSection actionMaterialsConfigSection = getConfig().getConfigurationSection("fperm-gui.action.materials");
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("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.EXP.EXPItem.Type", "EXP_BOTTLE", "EXPERIENCE_BOTTLE");
replaceStringInConfig("fupgrades.MainMenu.Spawners.SpawnerItem.Type", "MOB_SPAWNER", "SPAWNER");
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.undefined", "CYAN", "CYAN_STAINED_GLASS");
}
public void replaceStringInConfig(String path, String stringToReplace, String replacementString) {
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);
}
}
@ -515,6 +502,53 @@ public class SavageFactions extends MPlugin {
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
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) {
ArmorStand as = (ArmorStand) location.add(0.5, 1, 0.5).getWorld().spawnEntity(location, EntityType.ARMOR_STAND); //Spawn the ArmorStand
@ -524,12 +558,12 @@ public class SavageFactions extends MPlugin {
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
final ArmorStand armorStand = as;
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> {
Bukkit.getScheduler().scheduleSyncDelayedTask(SavageFactions.plugin, () -> {
armorStand.remove();
getLogger().info("Removing Hologram.");
}
, timeout * 20);
}

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
@ -43,9 +44,6 @@ public class CmdDisband extends FCommand {
return;
}
boolean isMyFaction = fme != null && faction == myFaction;
if (!fme.isAdminBypassing()) {
Access access = faction.getAccess(fme, PermissableAction.DISBAND);
if (fme.getRole() != Role.LEADER && access != Access.ALLOW) {
@ -78,11 +76,9 @@ public class CmdDisband extends FCommand {
} else {
//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) {
faction.disband(me);
faction.disband(me, PlayerDisbandReason.COMMAND);
}
}
}
@Override

View File

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

View File

@ -12,11 +12,13 @@ import org.bukkit.event.Cancellable;
public class FactionDisbandEvent extends FactionEvent implements Cancellable {
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));
this.sender = sender;
this.reason = reason;
}
public FPlayer getFPlayer() {
@ -27,7 +29,11 @@ public class FactionDisbandEvent extends FactionEvent implements Cancellable {
return sender;
}
@Override
public PlayerDisbandReason getReason() {
return reason;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@ -36,4 +42,11 @@ public class FactionDisbandEvent extends FactionEvent implements Cancellable {
public void setCancelled(boolean c) {
cancelled = c;
}
public enum PlayerDisbandReason {
COMMAND,
PLUGIN,
INACTIVITY,
LEAVE,
}
}

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ public class MiscUtil {
/// TODO create tag whitelist!!
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) {
if (!(entity instanceof Creature)) {
@ -100,25 +100,11 @@ public class MiscUtil {
}
switch (player.getRole()) {
case LEADER:
admins.add(player);
break;
case COLEADER:
admins.add(player);
break;
case MODERATOR:
moderators.add(player);
break;
case NORMAL:
normal.add(player);
break;
case RECRUIT:
recruit.add(player);
break;
case LEADER: admins.add(player); break;
case COLEADER: 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,7 +858,8 @@ public enum MultiversionMaterials {
ZOMBIE_VILLAGER_SPAWN_EGG("MONSTER_EGG", 0),
ZOMBIE_WALL_HEAD("SKULL", 0),
;
static int newV = - 1;
static int newV = - 1;
private static HashMap<String, MultiversionMaterials> cachedSearch = new HashMap<>();
String m;
int data;
@ -871,11 +872,13 @@ public enum MultiversionMaterials {
public static boolean isNewVersion() {
if (newV == 0) return false;
if (newV == 1) return true;
Material mat = Material.matchMaterial("RED_WOOL");
if (mat != null) {
newV = 1;
return true;
}
newV = 0;
return false;
}
@ -894,20 +897,13 @@ public enum MultiversionMaterials {
}
public static MultiversionMaterials fromString(String key) {
MultiversionMaterials xmat = null;
try {
xmat = MultiversionMaterials.valueOf(key);
return xmat;
return MultiversionMaterials.valueOf(key);
} catch (IllegalArgumentException e) {
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() {
@ -948,34 +944,21 @@ public enum MultiversionMaterials {
public boolean isDamageable(MultiversionMaterials type) {
String[] split = type.toString().split("_");
int length = split.length;
switch (split[length - 1]) {
switch (split[split.length - 1]) {
case "HELMET":
return true;
case "CHESTPLATE":
return true;
case "LEGGINGS":
return true;
case "BOOTS":
return true;
case "SWORD":
return true;
case "AXE":
return true;
case "PICKAXE":
return true;
case "SHOVEL":
return true;
case "HOE":
return true;
case "ELYTRA":
return true;
case "TURTLE_HELMET":
return true;
case "TRIDENT":
return true;
case "HORSE_ARMOR":
return true;
case "SHEARS":
return true;
default:
@ -985,10 +968,7 @@ public enum MultiversionMaterials {
public Material parseMaterial() {
Material mat = Material.matchMaterial(this.toString());
if (mat != null) {
return mat;
}
return Material.matchMaterial(m);
return mat != null ? mat:Material.matchMaterial(m);
}
}

View File

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

View File

@ -74,11 +74,7 @@ public abstract class MCommand<T extends MPlugin> {
}
public String getHelpShort() {
if (this.helpShort == null) {
return getUsageTranslation().toString();
}
return this.helpShort;
return this.helpShort != null ? this.helpShort:getUsageTranslation().toString();
}
public void setHelpShort(String val) {
@ -87,10 +83,9 @@ public abstract class MCommand<T extends MPlugin> {
public abstract TL getUsageTranslation();
// 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
this.sender = sender;
public void setCommandSender(CommandSender sender)
{
this.sender = sender;
if (sender instanceof Player) {
this.me = (Player) sender;
this.senderIsConsole = false;
@ -98,6 +93,12 @@ public abstract class MCommand<T extends MPlugin> {
this.me = null;
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.commandChain = commandChain;

View File

@ -334,6 +334,6 @@ public abstract class MPlugin extends JavaPlugin {
}
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),
UNDEFINED("Undefined", ChatColor.GRAY);
private String name;
private ChatColor color;
private final String name;
private final ChatColor color;
Access(String name, ChatColor color) {
this.name = name;
@ -22,12 +22,9 @@ public enum Access {
* @return
*/
public static Access fromString(String check) {
for (Access access : values()) {
if (access.name().equalsIgnoreCase(check)) {
for (Access access : values())
if (access.name().equalsIgnoreCase(check))
return access;
}
}
return null;
}
@ -43,5 +40,4 @@ public enum Access {
public String toString() {
return name();
}
}

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.*;
import org.bukkit.CropState;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockGrowEvent;
@ -12,48 +13,44 @@ import org.bukkit.material.Crops;
import java.util.concurrent.ThreadLocalRandom;
public class CropUpgrades implements Listener {
@EventHandler
public void onCropGrow(BlockGrowEvent e) {
FLocation floc = new FLocation(e.getBlock().getLocation());
Faction factionAtLoc = Board.getInstance().getFactionAt(floc);
if (factionAtLoc != Factions.getInstance().getWilderness()) {
if (!factionAtLoc.isWilderness()) {
int level = factionAtLoc.getUpgrade("Crop");
if (level != 0) {
if (level == 1) {
int chance = SavageFactions.plugin.getConfig().getInt("fupgrades.MainMenu.Crops.Crop-Boost.level-1");
int randomNum = ThreadLocalRandom.current().nextInt(1, 100 + 1);
if (randomNum <= chance) {
growCrop(e);
}
}
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);
}
}
int chance = -1;
switch (level)
{
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 (chance >= 0)
{
int randomNum = ThreadLocalRandom.current().nextInt(1, 100 + 1);
if (randomNum <= chance)
growCrop(e);
}
}
}
}
private void growCrop(BlockGrowEvent e) {
if (e.getBlock().getType().equals(SavageFactions.plugin.CROPS)) {
e.setCancelled(true);
Crops c = new Crops(CropState.RIPE);
org.bukkit.block.BlockState bs = e.getBlock().getState();
BlockState bs = e.getBlock().getState();
bs.setData(c);
bs.update();
}
Block below = e.getBlock().getLocation().subtract(0, 1, 0).getBlock();
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();
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;
import com.massivecraft.factions.*;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -9,6 +9,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
public class EXPUpgrade implements Listener {
@EventHandler
public void onDeath(EntityDeathEvent e) {
Entity killer = e.getEntity().getKiller();
@ -16,26 +17,24 @@ public class EXPUpgrade implements Listener {
if (killer == null || !(killer instanceof Player))
return;
Location loc = e.getEntity().getLocation();
Faction wild = Factions.getInstance().getWilderness();
FLocation floc = new FLocation(loc);
FLocation floc = new FLocation(e.getEntity().getLocation());
Faction faction = Board.getInstance().getFactionAt(floc);
if (faction != wild) {
if (!faction.isWilderness()) {
int level = faction.getUpgrade("Exp");
if (level != 0) {
if (level == 1) {
double multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-1");
spawnMoreExp(e, multiplier);
}
if (level == 2) {
double multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-2");
spawnMoreExp(e, multiplier);
}
if (level == 3) {
double multiplier = SavageFactions.plugin.getConfig().getDouble("fupgrades.MainMenu.EXP.EXP-Boost.level-3");
spawnMoreExp(e, multiplier);
}
double multiplier = -1;
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 (multiplier >= 0)
spawnMoreExp(e, multiplier);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,8 +4,10 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.cmd.CmdFly;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FPlayerStoppedFlying;
import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.event.LandClaimEvent;
import com.massivecraft.factions.event.PowerRegenEvent;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ;
@ -547,6 +549,7 @@ public abstract class MemoryFPlayer implements FPlayer {
} else if (hasFaction() && getFaction().isPowerFrozen()) {
return; // Don't let power regen if faction power is frozen.
}
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now;
@ -560,10 +563,7 @@ public abstract class MemoryFPlayer implements FPlayer {
Bukkit.getServer().getPluginManager().callEvent(powerRegenEvent);
if (!powerRegenEvent.isCancelled())
{
int millisPerMinute = 60 * 1000;
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
}
this.alterPower(millisPassed * Conf.powerPerMinute / 60000); // millisPerMinute : 60 * 1000
}
public void losePowerFromBeingOffline() {
@ -712,6 +712,9 @@ public abstract class MemoryFPlayer implements FPlayer {
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());
if (Conf.logFactionDisband) {
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
// return value is false on failure, true on success
Faction currentFaction = Board.getInstance().getFactionAt(flocation);
int ownedLand = forFaction.getLandRounded();
if (!this.canClaimForFactionAtLocation(forFaction, flocation, notifyFailure)) {
return false;
}
// 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();
double cost = 0.0;
@ -1159,7 +1158,7 @@ public abstract class MemoryFPlayer implements FPlayer {
}
LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this);
Bukkit.getServer().getPluginManager().callEvent(claimEvent);
Bukkit.getPluginManager().callEvent(claimEvent);
if (claimEvent.isCancelled()) {
return false;
}

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.zcore.persist;
import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ;
@ -236,13 +237,18 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
}
@Override
public void disband(Player disbander) {
disband(disbander, PlayerDisbandReason.PLUGIN);
}
@Override
public void disband(Player disbander, PlayerDisbandReason reason) {
boolean disbanderIsConsole = disbander == null;
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);
if (disbandEvent.isCancelled()) {
return;
@ -982,7 +988,13 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
// used when current leader is about to be removed from the faction;
// promotes new leader, or disbands faction if no other members left
@Override
public void promoteNewLeader() {
promoteNewLeader(false);
}
@Override
public void promoteNewLeader(boolean autoLeave) {
if (!this.isNormal()) {
return;
}
@ -1008,13 +1020,16 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
// no members left and faction isn't permanent, so disband it
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()) {
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());
} else { // promote new faction admin
if (oldLeader != null) {

View File

@ -2,14 +2,12 @@ package com.massivecraft.factions.zcore.util;
import com.massivecraft.factions.zcore.MPlugin;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class PermUtil {
public Map<String, String> permissionDescriptions = new HashMap<>();
@ -37,25 +35,15 @@ public class PermUtil {
public String getPermissionDescription(String perm) {
String desc = permissionDescriptions.get(perm);
if (desc == null) {
return TL.GENERIC_DOTHAT.toString();
}
return desc;
return desc != null ? desc:TL.GENERIC_DOTHAT.toString();
}
/**
* This method tests if me has a certain permission and returns true if me has. Otherwise false
*/
public boolean has(CommandSender me, String perm) {
if (me == null) {
return false;
}
if (!(me instanceof Player)) {
return me.hasPermission(perm);
}
return me.hasPermission(perm);
return me != null ? me.hasPermission(perm):false;
}
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_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_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_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_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"),
@ -506,7 +505,7 @@ public enum TL {
COMMAND_PROMOTE_DEMOTED("demoted"),
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_REVOKE("removed permanentpower status from"),
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_LOG("%1$s unclaimed all war zones."),
COMMAND_RULES_DISABLED_MSG("&cThis command is disabled!"),
COMMAND_RULES_DESCRIPTION("set/remove/add rules!"),
COMMAND_RULES_ADD_INVALIDARGS("Please include a rule!"),
@ -756,7 +754,6 @@ public enum TL {
COMMAND_RULES_SET_SUCCESS("&cRule set successfully!"),
COMMAND_RULES_CLEAR_SUCCESS("&cRule cleared successfully!"),
/**
* 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_COOLDOWN("&cThe warbanner is on cooldown for your faction!"),
WARBANNER_INVALIDLOC("&cYou can only use warbanners in enemy land or the warzone"),
/**
* ASCII compass (for chat map)
*/
@ -1014,7 +1012,7 @@ public enum TL {
@Override
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) {

View File

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