Cooldown and F Spam System Implemented

This commit is contained in:
Driftay 2019-06-02 14:28:42 -04:00
parent 4833cafa0e
commit 420d8e3321
25 changed files with 150 additions and 395 deletions

View File

@ -365,6 +365,12 @@ public interface FPlayer extends EconomyParticipator {
boolean checkIfNearbyEnemies();
public int getCooldown(String cmd);
public void setCooldown(String cmd, long cooldown);
public boolean isCooldownEnded(String cmd);
// -------------------------------
// Warmups

View File

@ -21,8 +21,6 @@ import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.fupgrades.*;
import com.massivecraft.factions.zcore.util.TextUtil;
import me.driftay.addons.bankxp.Deposit;
import me.driftay.addons.bankxp.Withdraw;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.*;
@ -79,6 +77,7 @@ public class SavageFactions extends MPlugin {
DIODE_BLOCK_ON, ENCHANTMENT_TABLE, FIREBALL;
SkriptAddon skriptAddon;
private boolean locked = false;
private boolean spam = false;
private Integer AutoLeaveTask = null;
private boolean hookedPlayervaults;
private ClipPlaceholderAPIManager clipPlaceholderAPIManager;
@ -99,6 +98,15 @@ public class SavageFactions extends MPlugin {
this.setAutoSave(val);
}
public boolean getSpam() {
return this.spam;
}
public void setSpam(boolean val) {
this.spam = val;
this.setAutoSave(val);
}
public void playSoundForAll(String sound) {
for (Player pl : Bukkit.getOnlinePlayers()) {
playSound(pl, sound);
@ -252,11 +260,6 @@ public class SavageFactions extends MPlugin {
getCommand(this.refCommand).setExecutor(this);
getCommand(this.refCommand).setTabCompleter(this);
if(getConfig().getBoolean("XP-BankNote-Enabled")) {
getCommand("withdraw").setExecutor(new Withdraw());
getCommand("bottle").setExecutor(new Withdraw());
getServer().getPluginManager().registerEvents(new Deposit(), this);
}
RegisteredServiceProvider<Economy> rsp = SavageFactions.this.getServer().getServicesManager().getRegistration(Economy.class);
SavageFactions.econ = rsp.getProvider();

View File

@ -16,6 +16,7 @@ public class CmdAHome extends FCommand {
this.permission = Permission.AHOME.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -23,6 +23,7 @@ public class CmdAdmin extends FCommand {
this.permission = Permission.ADMIN.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = false;

View File

@ -20,6 +20,7 @@ public class CmdAlts extends FCommand {
this.permission = Permission.ALTS.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = true;

View File

@ -16,6 +16,8 @@ public class CmdAltsList extends FCommand{
this.aliases.add("list");
this.permission = Permission.LIST.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = true;

View File

@ -19,6 +19,7 @@ public class CmdAnnounce extends FCommand {
this.permission = Permission.ANNOUNCE.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = true;

View File

@ -16,6 +16,7 @@ public class CmdAutoClaim extends FCommand {
this.permission = Permission.AUTOCLAIM.node;
this.disableOnLock = true;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -23,6 +23,7 @@ public class CmdBan extends FCommand {
this.permission = Permission.BAN.node;
this.disableOnLock = true;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -23,6 +23,7 @@ public class CmdBanlist extends FCommand {
this.permission = Permission.BAN.node;
this.disableOnLock = true;
this.disableOnSpam = false;
senderMustBePlayer = true;
senderMustBeMember = false;

View File

@ -24,6 +24,7 @@ public class CmdCreate extends FCommand {
this.permission = Permission.CREATE.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = true;
senderMustBeMember = false;
@ -41,6 +42,11 @@ public class CmdCreate extends FCommand {
return;
}
if (!fme.isCooldownEnded("create")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("create"));
return;
}
if (Factions.getInstance().isTagTaken(tag)) {
msg(TL.COMMAND_CREATE_INUSE);
return;
@ -108,6 +114,9 @@ public class CmdCreate extends FCommand {
if (SavageFactions.plugin.getConfig().getBoolean("fpaypal.Enabled")) {
this.fme.msg(TL.COMMAND_PAYPALSET_CREATED);
}
fme.setCooldown("create", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-create") * 1000));
if (Conf.useCustomDefaultPermissions) {
faction.setDefaultPerms();
if (Conf.usePermissionHints)

View File

@ -28,7 +28,7 @@ public class CmdDisband extends FCommand {
this.permission = Permission.DISBAND.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = false;
senderMustBeMember = false;
@ -46,6 +46,12 @@ public class CmdDisband extends FCommand {
return;
}
if (!fme.isCooldownEnded("disband")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("disband"));
return;
}
boolean isMyFaction = fme != null && faction == myFaction;
if (isMyFaction) {
@ -89,6 +95,7 @@ public class CmdDisband extends FCommand {
UtilFly.checkFly(this.fme, Board.getInstance().getFactionAt(new FLocation(follower)));
if (follower.getFaction() == faction) {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
fme.setCooldown("disband", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-disband") * 1000));
} else {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
}

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
@ -17,6 +18,7 @@ public class CmdOpen extends FCommand {
this.permission = Permission.OPEN.node;
this.disableOnLock = false;
this.disableOnSpam = true;
senderMustBePlayer = true;
@ -33,6 +35,11 @@ public class CmdOpen extends FCommand {
return;
}
if (!fme.isCooldownEnded("open")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("open"));
return;
}
myFaction.setOpen(this.argAsBool(0, !myFaction.getOpen()));
String open = myFaction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
@ -45,6 +52,7 @@ public class CmdOpen extends FCommand {
}
fplayer.msg(TL.COMMAND_OPEN_CHANGED, myFaction.getTag(fplayer.getFaction()), open);
}
fme.setCooldown("open", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-open") * 1000));
}
@Override

View File

@ -19,6 +19,7 @@ public class CmdShow extends FCommand {
public CmdShow() {
this.aliases.add("show");
this.aliases.add("who");
this.aliases.add("f");
// add defaults to /f show in case config doesnt have it
defaults.add("{header}");

View File

@ -0,0 +1,34 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdSpam extends FCommand {
public CmdSpam(){
this.aliases.add("spam");
this.optionalArgs.put("on/off", "flip");
this.permission = Permission.SPAM.node;
this.disableOnLock = false;
this.disableOnSpam = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
p.setSpam(this.argAsBool(0, !p.getSpam()));
msg(p.getSpam() ? TL.COMMAND_SPAM_ENABLED : TL.COMMAND_SPAM_DISABLED);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SPAM_DESCRIPTION;
}
}

View File

@ -21,6 +21,7 @@ public class CmdTag extends FCommand {
this.permission = Permission.TAG.node;
this.disableOnLock = true;
this.disableOnSpam = true;
senderMustBePlayer = true;
senderMustBeMember = false;
@ -33,6 +34,13 @@ public class CmdTag extends FCommand {
public void perform() {
String tag = this.argAsString(0);
if (!fme.isCooldownEnded("tag")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("tag"));
return;
}
// TODO does not first test cover selfcase?
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
msg(TL.COMMAND_TAG_TAKEN);
@ -78,7 +86,7 @@ public class CmdTag extends FCommand {
fplayer.msg(TL.COMMAND_TAG_CHANGED, fme.getColorTo(faction) + oldtag, myFaction.getTag(faction));
}
}
fme.setCooldown("tag", System.currentTimeMillis() + (SavageFactions.plugin.getConfig().getInt("fcooldowns.f-tag") * 1000));
FTeamWrapper.updatePrefixes(myFaction);
}

View File

@ -108,6 +108,7 @@ public class FCmdRoot extends FCommand {
public CmdStrike cmdStrike = new CmdStrike();
public CmdStrikeSet cmdStrikeSet = new CmdStrikeSet();
public CmdAlts cmdAlts = new CmdAlts();
public CmdSpam cmdSpam = new CmdSpam();
@ -222,6 +223,7 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdChest);
this.addSubCommand(this.cmdSetBanner);
this.addSubCommand(this.cmdStrikeSet);
this.addSubCommand(this.cmdSpam);
if(SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled")){

View File

@ -18,6 +18,7 @@ public abstract class FCommand extends MCommand<SavageFactions> {
public static final SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString());
public boolean disableOnLock;
public boolean disableOnSpam;
public FPlayer fme;
public Faction myFaction;
@ -34,6 +35,7 @@ public abstract class FCommand extends MCommand<SavageFactions> {
// Due to safety reasons it defaults to disable on lock.
disableOnLock = true;
disableOnSpam = false;
// The money commands must be disabled if money should not be used.
isMoneyCommand = false;
@ -69,6 +71,11 @@ public abstract class FCommand extends MCommand<SavageFactions> {
return false;
}
if(p.getSpam() && this.disableOnSpam){
msg("<b>Anti-Spam is currently enabled! Please try again later.");
return false;
}
if (this.isMoneyCommand && !Conf.econEnabled) {
msg("<b>Faction economy features are disabled on this server.");
return false;

View File

@ -78,6 +78,7 @@ public enum Permission {
RELATION("relation"),
RELOAD("reload"),
SAVE("save"),
SPAM("spam"),
SETHOME("sethome"),
SETHOME_ANY("sethome.any"),
SETSTRIKES("setstrikes"),

View File

@ -28,10 +28,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.text.DecimalFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;
/**
@ -44,7 +41,7 @@ import java.util.UUID;
*/
public abstract class MemoryFPlayer implements FPlayer {
protected HashMap<String, Long> commandCooldown = new HashMap<>();
public boolean inVault = false;
protected String factionId;
protected Role role;
@ -158,6 +155,33 @@ public abstract class MemoryFPlayer implements FPlayer {
this.deaths = getPlayer().getStatistic(Statistic.DEATHS);
}
public int getCooldown(String cmd) {
int seconds = 0;
if (this.getPlayer().isOp())
return 0;
if (commandCooldown.containsKey(cmd))
seconds = (int) ((this.commandCooldown.get(cmd) - System.currentTimeMillis()) / 1000);
return seconds;
}
public void setCooldown(String cmd, long cooldown) {
if (this.getPlayer().isOp())
return;
this.commandCooldown.put(cmd, cooldown);
}
public boolean isCooldownEnded(String cmd) {
if (this.getPlayer().isOp())
return true;
if (!commandCooldown.containsKey(cmd))
return true;
else if (commandCooldown.containsKey(cmd) && commandCooldown.get(cmd) <= System.currentTimeMillis())
return true;
return false;
}
public Faction getFaction() {
if (this.factionId == null) {
this.factionId = "0";

View File

@ -410,6 +410,11 @@ public enum TL {
COMMAND_LIST_ONLINEFACTIONLESS("Online factionless: "),
COMMAND_LIST_DESCRIPTION("&a&l» &7See a list of the factions"),
COMMAND_SPAM_ENABLED("&c&l[!]&7 Factions Anti-Spam is now&a enabled"),
COMMAND_SPAM_DISABLED("&c&l[!]&7 Factions Anti-Spam in now&c disabled"),
COMMAND_SPAM_DESCRIPTION("enable antispam system"),
COMMAND_LOCK_LOCKED("&c&l[!]&7 Factions is now&c locked"),
COMMAND_LOCK_UNLOCKED("&c&l[!]&7 Factions in now&a unlocked"),
COMMAND_LOCK_DESCRIPTION("Lock all write stuff. Apparently."),
@ -627,6 +632,7 @@ public enum TL {
COMMAND_SETMAXVAULTS_DESCRIPTION("Set max vaults for a Faction."),
COMMAND_SETMAXVAULTS_SUCCESS("&aSet max vaults for &e%s &ato &b%d"),
COMMAND_ONCOOOLDOWN("&c&l[!] &7You cannot use this command for another &b%1$s &7seconds."),
COMMAND_SETSTRIKES_FAILURE("&c&l[!]&7 &c{faction} does not exist."),
COMMAND_SETSTRIKES_BROADCAST("&c&l[!]&7 &c{faction} has received a strike for {reason}"),

View File

@ -1,103 +0,0 @@
package me.driftay.addons.bankxp;
import com.massivecraft.factions.SavageFactions;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Scanner;
public class Deposit implements Listener {
@EventHandler
public void DepositEvent(PlayerInteractEvent e) {
Player p = e.getPlayer();
Action a = e.getAction();
ItemStack mainhand = p.getInventory().getItemInHand();
if (mainhand != null && (a.equals(Action.RIGHT_CLICK_AIR) || a.equals(Action.RIGHT_CLICK_BLOCK)) && mainhand.hasItemMeta() && mainhand.getItemMeta().hasLore()) {
try {
Material item = Material.getMaterial(SavageFactions.plugin.getConfig().getString("Banknote.Item.ID"));
if (mainhand.getType() == item) {
this.takeBanknote(e, mainhand);
return;
}
} catch (Exception e3) {
try {
Material item2 = Material.getMaterial(String.valueOf(SavageFactions.plugin.getConfig().getInt("Banknote.Item.ID")));
if (mainhand.getType() == item2) {
this.takeBanknote(e, mainhand);
return;
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
try {
Material item = Material.getMaterial(SavageFactions.plugin.getConfig().getString("XpBottle.Item.ID"));
if (mainhand.getType() == item) {
this.takeXpBottle(e, mainhand);
}
} catch (Exception e3) {
try {
Material item2 = Material.getMaterial(String.valueOf(SavageFactions.plugin.getConfig().getInt("XpBottle.Item.ID")));
if (mainhand.getType() == item2) {
this.takeXpBottle(e, mainhand);
}
} catch (Exception e2) {
e.getPlayer().sendMessage("&c&l[!] &7Unknown Command!");
e2.printStackTrace();
}
}
}
}
public void takeXpBottle(PlayerInteractEvent e, ItemStack mainhand) {
Player p = e.getPlayer();
ItemMeta meta = mainhand.getItemMeta();
for (String lore : meta.getLore()) {
String newlore = ChatColor.stripColor(lore.replace(",", ""));
if (newlore.startsWith(ChatColor.stripColor(SavageFactions.plugin.getConfig().getString("XpBottle.Item.Checks-for")))) {
try {
Scanner in = new Scanner(newlore).useDelimiter("[^0-9]+");
int value = in.nextInt() * mainhand.getAmount();
ExperienceFIX.setTotalExperience(p, ExperienceFIX.getTotalExperience(p) + value);
p.sendMessage(color(SavageFactions.plugin.getConfig().getString("Messages.xpbottle.deposit")).replace("{exp}", String.valueOf(value)).replace("{exp-balance}", String.valueOf(p.getTotalExperience())));
e.setCancelled(true);
p.getInventory().removeItem(mainhand);
} catch (Exception x) {
}
}
}
}
public void takeBanknote(PlayerInteractEvent e, ItemStack mainhand) {
Player p = e.getPlayer();
ItemMeta meta = mainhand.getItemMeta();
for (String lore : meta.getLore()) {
String newlore = ChatColor.stripColor(lore.replace(",", ""));
if (newlore.startsWith(ChatColor.stripColor(SavageFactions.plugin.getConfig().getString("Banknote.Item.Checks-for")))) {
try {
Scanner in = new Scanner(newlore).useDelimiter("[^0-9]+");
long value = in.nextLong() * mainhand.getAmount();
SavageFactions.econ.depositPlayer( p, (double) value);
p.sendMessage(color(SavageFactions.plugin.getConfig().getString("Messages.banknote.deposit")).replace("{money}", SavageFactions.econ.format((double) value)).replace("{balance}", SavageFactions.econ.format(SavageFactions.econ.getBalance(p))));
e.setCancelled(true);
p.getInventory().remove(mainhand);
} catch (Exception x) {
}
}
}
}
public String color(String message){
message = ChatColor.translateAlternateColorCodes('&', message);
return message;
}
}

View File

@ -1,70 +0,0 @@
package me.driftay.addons.bankxp;
import org.bukkit.entity.Player;
public class ExperienceFIX {
public static void setTotalExperience(Player player, int exp) {
if (exp < 0) {
throw new IllegalArgumentException("Experience is negative!");
}
player.setExp(0.0f);
player.setLevel(0);
player.setTotalExperience(0);
int amount = exp;
while (amount > 0) {
int expToLevel = getExpAtLevel(player);
amount -= expToLevel;
if (amount >= 0) {
player.giveExp(expToLevel);
} else {
amount += expToLevel;
player.giveExp(amount);
amount = 0;
}
}
}
private static int getExpAtLevel(Player player) {
return getExpAtLevel(player.getLevel());
}
public static int getExpAtLevel(int level) {
if (level <= 15) {
return 2 * level + 7;
}
if (level >= 16 && level <= 30) {
return 5 * level - 38;
}
return 9 * level - 158;
}
public static int getExpToLevel(int level) {
int currentLevel = 0;
int exp = 0;
while (currentLevel < level) {
exp += getExpAtLevel(currentLevel);
++currentLevel;
}
if (exp < 0) {
exp = Integer.MAX_VALUE;
}
return exp;
}
public static int getTotalExperience(Player player) {
int exp = Math.round(getExpAtLevel(player) * player.getExp());
for (int currentLevel = player.getLevel(); currentLevel > 0; --currentLevel, exp += getExpAtLevel(currentLevel)) {
}
if (exp < 0) {
exp = Integer.MAX_VALUE;
}
return exp;
}
public static int getExpUntilNextLevel(Player player) {
int exp = Math.round(getExpAtLevel(player) * player.getExp());
int nextLevel = player.getLevel();
return getExpAtLevel(nextLevel) - exp;
}
}

View File

@ -1,162 +0,0 @@
package me.driftay.addons.bankxp;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class Withdraw implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("withdraw")) {
if (sender.hasPermission("factions.withdraw.money")) {
Player p;
if ((p = Bukkit.getPlayer(sender.getName())) != null) {
if (args.length == 1) {
long max = SavageFactions.plugin.getConfig().getLong("Banknote.Range.MAX");
long min = SavageFactions.plugin.getConfig().getLong("Banknote.Range.MIN");
List<String> lore = SavageFactions.plugin.getConfig().getStringList("Banknote.Item.Display.lore");
String name = SavageFactions.plugin.getConfig().getString("Banknote.Item.Display.name");
boolean glow = SavageFactions.plugin.getConfig().getBoolean("Banknote.Item.Display.glow");
try {
long value = Long.parseLong(args[0]);
if (value >= min && max >= value) {
if (value <= SavageFactions.econ.getBalance(p)) {
try {
ItemStack item = new ItemStack(Material.getMaterial(SavageFactions.plugin.getConfig().getString("Banknote.Item.ID")));
item.setDurability((short) SavageFactions.plugin.getConfig().getInt("Banknote.Item.DamageValue"));
p.getInventory().addItem(this.Item(p.getName(), p, item, name, lore, value, (int) value, glow));
SavageFactions.econ.withdrawPlayer(p, (double) value);
this.banknotemsg(p, value);
} catch (Exception e) {
try {
ItemStack item2 = new ItemStack(Material.getMaterial(String.valueOf(SavageFactions.plugin.getConfig().getInt("Banknote.Item.ID"))));
item2.setDurability((short) SavageFactions.plugin.getConfig().getInt("Banknote.Item.DamageValue"));
p.getInventory().addItem(this.Item(p.getName(), p, item2, name, lore, value, (int) value, glow));
SavageFactions.econ.withdrawPlayer(p, (double) value);
this.banknotemsg(p, value);
} catch (Exception x2) {
sender.sendMessage("&c&l[!] &7Unknown Command!");
e.printStackTrace();
}
}
} else {
p.sendMessage(TL.BANKNOTE_WITHDRAW_NOT_ENOUGH.toString());
}
} else {
sender.sendMessage(color("&c&l[!] &b" + args[0] + " &7is not in range of " + min + " - " + max));
//sender.sendMessage(color(SavageFactions.plugin.getConfig().getString("Messages.Not-In-Range")).replace("{min}", String.valueOf(min)).replace("{max}", String.valueOf(max)).replace("{arg}", args[0]));
}
} catch (Exception e2) {
sender.sendMessage(color("&c&l[!] &b" + args[0] + " &7is not a number!"));
}
} else {
sender.sendMessage(TL.BANKNOTE_WITHDRAW_NO_ARGS.toString());
}
} else {
sender.sendMessage(color("&4Umm... Your not a player, you don't have an inventory to give this too"));
}
return true;
}
sender.sendMessage(TL.GENERIC_NOPERMISSION.toString());
}
if (cmd.getName().equalsIgnoreCase("bottle")) {
if (sender.hasPermission("factions.withdraw.exp")) {
Player p;
if ((p = Bukkit.getPlayer(sender.getName())) != null) {
if (args.length == 1) {
int max2 = SavageFactions.plugin.getConfig().getInt("XpBottle.Range.MAX");
int min2 = SavageFactions.plugin.getConfig().getInt("XpBottle.Range.MIN");
List<String> lore2 = SavageFactions.plugin.getConfig().getStringList("XpBottle.Item.Display.lore");
String name2 = SavageFactions.plugin.getConfig().getString("XpBottle.Item.Display.name");
boolean glow2 = SavageFactions.plugin.getConfig().getBoolean("XpBottle.Item.Display.glow");
try {
int value2 = Integer.parseInt(args[0]);
if (value2 >= min2 && max2 >= value2) {
if (value2 <= ExperienceFIX.getTotalExperience(p)) {
try {
ItemStack item3 = new ItemStack(Material.getMaterial(SavageFactions.plugin.getConfig().getString("XpBottle.Item.ID")));
item3.setDurability((short) SavageFactions.plugin.getConfig().getInt("XpBottle.Item.DamageValue"));
p.getInventory().addItem(this.Item(p.getName(), p, item3, name2, lore2, value2, value2, glow2));
ExperienceFIX.setTotalExperience(p, ExperienceFIX.getTotalExperience(p) - value2);
this.xpbottlemsg(p, value2);
} catch (Exception e3) {
try {
ItemStack item4 = new ItemStack(Material.getMaterial(String.valueOf(SavageFactions.plugin.getConfig().getInt("XpBottle.Item.ID"))));
item4.setDurability((short) SavageFactions.plugin.getConfig().getInt("XpBottle.Item.DamageValue"));
p.getInventory().addItem(this.Item(p.getName(), p, item4, name2, lore2, value2, value2, glow2));
ExperienceFIX.setTotalExperience(p, value2);
this.xpbottlemsg(p, value2);
} catch (Exception x) {
sender.sendMessage("&c&l[!] &7Unknown Command!");
x.printStackTrace();
}
}
} else {
p.sendMessage(TL.XPBOTTLE_NOT_ENOUGH.toString());
}
} else {
sender.sendMessage(color("&c&l[!] &b" + args[0] + " &7is not in range of " + min2 + " - " + max2));
//sender.sendMessage(color(SavageFactions.plugin.getConfig().getString("Messages.Not-In-Range")).replace("{min}", String.valueOf(min2)).replace("{max}", String.valueOf(max2)).replace("{arg}", args[0]));
}
} catch (Exception e4) {
sender.sendMessage(color("&c&l[!] &b" + args[0] + " &7is not a number!"));
}
} else {
sender.sendMessage(TL.XPBOTTLE_WITHDRAW_NO_ARGS.toString());
}
} else {
sender.sendMessage(color("&4Umm... Your not a player, you don't have an inventory to give this too"));
}
} else {
sender.sendMessage(TL.GENERIC_NOPERMISSION.toString());
}
return true;
}
return true;
}
private void banknotemsg(Player p, long l) {
p.sendMessage(color(SavageFactions.plugin.getConfig().getString("Messages.banknote.withdraw")).replace("{money}", SavageFactions.econ.format((double) l)).replace("{balance}", SavageFactions.econ.format(SavageFactions.econ.getBalance(p))).replace("{player}", p.getName()).replace("{displayname}", p.getDisplayName()));
}
private void xpbottlemsg(Player p, int i) {
p.sendMessage(color(SavageFactions.plugin.getConfig().getString("Messages.xpbottle.withdraw")).replace("{exp}", String.valueOf(i)).replace("{exp-balance}", String.valueOf(p.getTotalExperience())).replace("{player}", p.getName()).replace("{displayname}", p.getDisplayName()));
}
public String color(String message) {
message = ChatColor.translateAlternateColorCodes('&', message);
return message;
}
ItemStack Item(String getPlayer, Player p, ItemStack Item, String name, List<String> lore, long l, int i, boolean b) {
ItemMeta meta = Item.getItemMeta();
meta.setDisplayName(color(name.replace("{player}", getPlayer).replace("{money}", SavageFactions.econ.format((double) l)).replace("{exp}", String.valueOf(i)).replace("{balance}", SavageFactions.econ.format(SavageFactions.econ.getBalance(p)))));
List<String> list = new ArrayList<String>();
for (String s : lore) {
String old = color(s.replace("{player}", getPlayer).replace("{money}", SavageFactions.econ.format((double) l)).replace("{exp}", String.valueOf(i)).replace("{balance}", SavageFactions.econ.format(SavageFactions.econ.getBalance(p))));
list.add(old);
}
lore.addAll(list);
meta.setLore(list);
if (b) {
meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 0, true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
Item.setItemMeta(meta);
return Item;
}
}

View File

@ -702,52 +702,6 @@ fwarp-gui:
lore:
-
############################################################
# +------------------------------------------------------+ #
# | BankNote/XPBottles | #
# +------------------------------------------------------+ #
############################################################
XP-BankNote-Enabled: true
Banknote:
Item:
Display:
glow: true
name: '&aBanknote'
lore:
- '&eValue: &6{money}'
- '&eOwner: &6{player}'
- '&fThis is just a peace of paper'
ID: PAPER
DamageValue: 0
Checks-for: 'Value: '
Range:
MIN: 1000
MAX: 9999999999
XpBottle:
Item:
Display:
glow: true
name: '&eXpBottle'
lore:
- '&eValue: &6{exp} EXP'
- '&eOwner: &6{player}'
- '&fThis is just a XpBottle'
ID: EXP_BOTTLE
DamageValue: 0
Checks-for: 'Value: '
Range:
MIN: 100
MAX: 2147483647
Messages:
banknote:
withdraw: '&bYou have withdrawn &d{money} &bfrom your balance, you now have &d{balance}'
deposit: '&bYou have deposited &d{money} &bto your balance, you now have &d{balance}'
xpbottle:
withdraw: '&bYou have withdrawn &d{exp} &bfrom your experience, you know have &d{exp-balance}'
deposit: '&bYou have deposited &d{exp} &bto your experience, you know have &d{exp-balance}'
############################################################
# +------------------------------------------------------+ #
# | Faction Creation/Disband Broadcast | #
@ -816,6 +770,17 @@ fnear:
Enabled: true
Radius: 50
############################################################
# +------------------------------------------------------+ #
# | Faction Command Cooldowns | #
# +------------------------------------------------------+ #
############################################################
fcooldowns:
f-open: 5
f-disband: 10
f-create: 10
f-tag: 10
############################################################
# +------------------------------------------------------+ #
# | Falling Block Fix | #