diff --git a/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java b/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java index e83eabf74..3bfb1bf00 100644 --- a/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java +++ b/Plugins/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java @@ -39,7 +39,7 @@ public class PlayerCache catch (Exception exception) { System.out.println("Error adding player info in PlayerCache : " + exception.getMessage()); - exception.printStackTrace(); +// exception.printStackTrace(); } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java index d76d2428e..5a7388fc9 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java @@ -9,50 +9,59 @@ import mineplex.core.common.util.UtilPlayer; public enum Rank { //Staff - LT("Leader", ChatColor.GOLD), - OWNER("Owner", ChatColor.GOLD), - DEVELOPER("Dev", ChatColor.GOLD), - ADMIN("Admin", ChatColor.GOLD), - JNR_DEV("Jr.Dev", ChatColor.GOLD), - SUPPORT("Support", ChatColor.BLUE), - SNR_MODERATOR("Sr.Mod", ChatColor.GOLD), - MODERATOR("Mod", ChatColor.GOLD), - HELPER("Trainee", ChatColor.DARK_AQUA), - MAPLEAD("MapLead", ChatColor.BLUE), - MAPDEV("Builder", ChatColor.BLUE), - MEDIA("Media", ChatColor.BLUE), + LT("Leader", ChatColor.GOLD, "Leaders are in charge of special teams\nsuch as the whole staff team or the support!"), + OWNER("Owner", ChatColor.GOLD, "Owners are the Founders of Mineplex\nand they all manage different parts of it!"), + DEVELOPER("Dev", ChatColor.GOLD, "Developers make new games,\nand new features for you to enjoy"), + ADMIN("Admin", ChatColor.GOLD, "Administrators have their own\nSenior Moderator team that they lead!"), + JNR_DEV("Jr.Dev", ChatColor.GOLD, "Junior Developers make new games,\nand new features for you to enjoy"), + SUPPORT("Support", ChatColor.BLUE, "Support Agents take care of all the tickets\nthat get sent to mineplex.com/support"), + CMOD("C.Mod", ChatColor.GOLD, "Clan Moderators are Senior Moderators in\nthe Clans Management team.\nThey mainly moderate only the Clans servers.\nThey are around to help you with any problems on Clans servers."), + SNR_MODERATOR("Sr.Mod", ChatColor.GOLD, "Senior Moderators are in a special\nSenior Moderator team where they have to fulfill team tasks.\nThey are similar to Moderators who you can always ask for help!\nIf you have any questions, just message them using /a"), + MODERATOR("Mod", ChatColor.GOLD, "Moderators are here to moderate\nand help players with any concerns they have.\nIf you have any questions, just message them using /a"), + HELPER("Trainee", ChatColor.DARK_AQUA, "Trainees are staff in training,\nand are here to help players and moderate!\nIf you have any questions, just message them using /a"), + MAPLEAD("MapLead", ChatColor.BLUE, "Leader of the Official Build team"), + MAPDEV("Builder", ChatColor.BLUE, "Official Mineplex Map Builders"), + MEDIA("Media", ChatColor.BLUE, "Official Mineplex Artist and/or Designer"), - EVENT("Event", ChatColor.WHITE), + EVENT("Event", ChatColor.WHITE, "???"), //Media - YOUTUBE("YouTube", ChatColor.RED), - YOUTUBE_SMALL("YT", ChatColor.DARK_PURPLE), - TWITCH("Twitch", ChatColor.DARK_PURPLE), + YOUTUBE("YouTube", ChatColor.RED, "Official Mineplex Youtuber"), + YOUTUBE_SMALL("YT", ChatColor.DARK_PURPLE, "Youtube Content Creators"), + TWITCH("Twitch", ChatColor.DARK_PURPLE, "Official Twitch Live Streamer"), //Player - TITAN("Titan", ChatColor.RED, true), - LEGEND("Legend", ChatColor.GREEN, true), - HERO("Hero", ChatColor.LIGHT_PURPLE, true), - ULTRA("Ultra", ChatColor.AQUA, true), - ALL("", ChatColor.WHITE); + TITAN("Titan", ChatColor.RED, true, "Mineplex's fourth premium rank\nBuy Titan at mineplex.com/shop"), + LEGEND("Legend", ChatColor.GREEN, true, "Mineplex's third premium rank\nBuy Legend at mineplex.com/shop"), + HERO("Hero", ChatColor.LIGHT_PURPLE, true, "Mineplex's second premium rank\nBuy Hero at mineplex.com/shop"), + ULTRA("Ultra", ChatColor.AQUA, true, "Mineplex's first premium rank\nBuy Ultra at mineplex.com/shop"), + ALL("", ChatColor.WHITE, null); private ChatColor _color; private boolean _donor; + private String _info; public String Name; - Rank(String name, ChatColor color) + Rank(String name, ChatColor color, String info) { _color = color; Name = name; _donor = false; + _info = info; } - Rank(String name, ChatColor color, boolean donor) + Rank(String name, ChatColor color, boolean donor, String info) { _color = color; Name = name; _donor = donor; + _info = info; + } + + public String getInfo() + { + return _info; } public boolean has(Rank rank) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/events/ServerShutdownEvent.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/events/ServerShutdownEvent.java new file mode 100644 index 000000000..70bf8f99d --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/events/ServerShutdownEvent.java @@ -0,0 +1,33 @@ +package mineplex.core.common.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.java.JavaPlugin; + +public class ServerShutdownEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private JavaPlugin _plugin; + + public ServerShutdownEvent(JavaPlugin plugin) + { + _plugin = plugin; + } + + public JavaPlugin getPlugin() + { + return _plugin; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/ColorFader.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/ColorFader.java new file mode 100644 index 000000000..01143886b --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/ColorFader.java @@ -0,0 +1,62 @@ +package mineplex.core.common.util; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class ColorFader { + + private final int _loopsBetween; + + private final List _colors; + private final LoopIterator _iterator; + private int _loopsSinceLast; + + public ColorFader(int loopsBetweenColors, RGBData... colors) + { + this(loopsBetweenColors, Arrays.asList(colors)); + } + + public ColorFader(int loopsBetweenColors, List colors) + { + _loopsBetween = loopsBetweenColors; + + _colors = new LinkedList<>(colors); + _iterator = new LoopIterator<>(_colors); + } + + public RGBData next() + { + RGBData rgb; + + if (_loopsSinceLast >= _loopsBetween) + { + rgb = _iterator.next(); + _loopsSinceLast = 0; + } + else + { + int redStep = (_iterator.peekNext().getFullRed() - _iterator.current().getFullRed()) / _loopsBetween; + int greenStep = (_iterator.peekNext().getFullGreen() - _iterator.current().getFullGreen()) / _loopsBetween; + int blueStep = (_iterator.peekNext().getFullBlue() - _iterator.current().getFullBlue()) / _loopsBetween; + + int red = _iterator.current().getFullRed(); + int green = _iterator.current().getFullGreen(); + int blue = _iterator.current().getFullBlue(); + + for (int i = 0; i < _loopsSinceLast; i++) + { + red += redStep; + green += greenStep; + blue += blueStep; + } + + rgb = new RGBData(red, green, blue); + } + + _loopsSinceLast++; + + return rgb; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java index fd2a34ec6..998b57d7c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java @@ -2,6 +2,8 @@ package mineplex.core.common.util; import mineplex.core.common.Rank; +import java.util.LinkedList; + import org.bukkit.ChatColor; public class F @@ -42,9 +44,9 @@ public class F return C.sysHead + head + "> " + C.sysBody + body; } - public static String elem(String elem) + public static String elem(Object elem) { - return C.mElem + elem + ChatColor.RESET + C.mBody; + return C.mElem + elem.toString() + ChatColor.RESET + C.mBody; } public static String name(String elem) @@ -198,5 +200,19 @@ public class F return out; } - + public static String vowelAN(String word) + { + return word.toLowerCase().startsWith("a") + || word.toLowerCase().startsWith("A") + || word.toLowerCase().startsWith("e") + || word.toLowerCase().startsWith("E") + || word.toLowerCase().startsWith("i") + || word.toLowerCase().startsWith("I") + || word.toLowerCase().startsWith("o") + || word.toLowerCase().startsWith("O") + || word.toLowerCase().startsWith("u") + || word.toLowerCase().startsWith("U") + ? "an" : "a"; + } + } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/LoopIterator.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/LoopIterator.java new file mode 100644 index 000000000..b5829a851 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/LoopIterator.java @@ -0,0 +1,83 @@ +package mineplex.core.common.util; + +import java.util.List; + +public class LoopIterator +{ + private List _list; + private int _pointer; + + public LoopIterator(List list) + { + _list = list; + } + + public T next() + { + if (_list.isEmpty()) + { + return null; + } + + if (++_pointer == _list.size()) + { + _pointer = 0; + } + + return _list.get(_pointer); + } + + public T peekNext() + { + if (_list.isEmpty()) + { + return null; + } + + int pointer = _pointer; + + if (++pointer == _list.size()) + { + pointer = 0; + } + + return _list.get(pointer); + } + + public T peekPrev() + { + if (_list.isEmpty()) + { + return null; + } + + int pointer = _pointer; + + if (--pointer < 0) + { + pointer = _list.size() - 1; + } + + return _list.get(pointer); + } + + public T prev() + { + if (_list.isEmpty()) + { + return null; + } + + if (--_pointer < 0) + { + _pointer = _list.size() - 1; + } + + return _list.get(_pointer); + } + + public T current() + { + return _list.get(_pointer); + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NonFinalInteger.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NonFinalInteger.java new file mode 100644 index 000000000..6638cbed9 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NonFinalInteger.java @@ -0,0 +1,33 @@ +package mineplex.core.common.util; + +public class NonFinalInteger +{ + private int _value; + + public NonFinalInteger() + { + this(0); + } + + public NonFinalInteger(int value) + { + _value = value; + } + + public NonFinalInteger add(int value) + { + _value += value; + return this; + } + + public NonFinalInteger subtract(int value) + { + _value -= value; + return this; + } + + public int get() + { + return _value; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumericalPulser.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumericalPulser.java new file mode 100644 index 000000000..e0de3e7d2 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NumericalPulser.java @@ -0,0 +1,42 @@ +package mineplex.core.common.util; + +public class NumericalPulser +{ + private double _min; + private double _max; + private double _modifyPerCall; + + private double _cur; + private boolean _up; + + public NumericalPulser(double min, double max, double modify) + { + _min = min; + _max = max; + _modifyPerCall = modify; + } + + public double pulse() + { + if (_up) + { + _cur = UtilMath.clamp(_cur += _modifyPerCall, _min, _max); + + if (_cur >= _max) + { + _up = false; + } + } + else + { + _cur = UtilMath.clamp(_cur -= _modifyPerCall, _min, _max); + + if (_cur <= _min) + { + _up = true; + } + } + + return _cur; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RGBData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RGBData.java new file mode 100644 index 000000000..912516d17 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RGBData.java @@ -0,0 +1,53 @@ +package mineplex.core.common.util; + +public class RGBData +{ + private double _red; + private double _green; + private double _blue; + + public RGBData(int red, int green, int blue) + { + _red = UtilMath.clamp(((double) red) / 255.d, 0, 1); + _green = UtilMath.clamp(((double) green) / 255.d, 0, 1); + _blue = UtilMath.clamp(((double) blue) / 255.d, 0, 1); + } + + public int getFullRed() + { + return (int) (_red * 255); + } + + public int getFullGreen() + { + return (int) (_green * 255); + } + + public int getFullBlue() + { + return (int) (_blue * 255); + } + + public double getRed() + { + return _red; + } + + public double getGreen() + { + return _green; + } + + public double getBlue() + { + return _blue; + } + + public String toString() + { + return "RGB[" + + "red=" + (int) (_red * 255) + ", " + + "green=" + (int) (_green * 255) + ", " + + "blue=" + (int) (_blue * 255) + "]"; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index 6045f4d9e..40f1147c9 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -15,7 +15,7 @@ import org.bukkit.entity.Player; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; -import net.minecraft.server.v1_8_R3.EnumDirection; +import net.minecraft.server.v1_8_R3.AxisAlignedBB; public class UtilAlg { @@ -510,4 +510,9 @@ public class UtilAlg Math.toRadians(UtilAlg.GetYaw(vector)), 0); } + + public static AxisAlignedBB toBoundingBox(Location a, Location b) + { + return new AxisAlignedBB(a.getX(), a.getY(), a.getZ(), b.getX(), b.getY(), b.getZ()); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java index e04ddf689..32244ece9 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java @@ -7,6 +7,9 @@ import org.bukkit.ChatColor; */ public class UtilColor { + public static final RGBData RgbRed = hexToRgb(0xee0100); + public static final RGBData RgbGold = hexToRgb(0xffd014); + public static final RGBData RgbLightBlue = hexToRgb(0x61fff7); public static byte chatColorToClayData(ChatColor chatColor) { @@ -66,4 +69,19 @@ public class UtilColor return 0; } } + + public static RGBData hexToRgb(int hex) + { + return new RGBData(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF); + } + + public static int rgbToHex(RGBData rgb) + { + return (rgb.getFullRed() << 16 | rgb.getFullGreen() << 8 | rgb.getFullBlue()); + } + + public static int rgbToHex(int red, int green, int blue) + { + return (red << 16 | green << 8 | blue); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index 3d48c098f..5a4ee4a42 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -116,4 +116,15 @@ public class UtilMath { return num < min ? min : (num > max ? max : num); } + + public static double random(double min, double max) + { + min = Math.abs(min); + + int rand = -random.nextInt((int)(min * 100)); + + rand += random.nextInt((int)(max * 100)); + + return ((double) rand) / 100.d; + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index f1e17e2df..268a3cbc8 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -14,6 +14,7 @@ import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory; diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java index 2791c275f..360a418c2 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java @@ -13,6 +13,7 @@ import mineplex.core.common.CurrencyType; import org.apache.commons.lang.WordUtils; import org.bukkit.ChatColor; +import org.bukkit.entity.Player; public class UtilText { @@ -167,7 +168,7 @@ public class UtilText return fillLine(" ", div) + string + fillLine(" ", div); } - + public static String alignRight(String string, LineFormat lineFormat) { int length = getLength(string); @@ -650,5 +651,28 @@ public class UtilText { return arrayToString(array, null); } + + public static String getProgress(String prefix, double amount, String suffix, boolean progressDirectionSwap) + { + if (progressDirectionSwap) + amount = 1 - amount; + + //Generate Bar + int bars = 24; + String progressBar = C.cGreen + ""; + boolean colorChange = false; + for (int i=0 ; i= amount) + { + progressBar += C.cRed; + colorChange = true; + } + + progressBar += "▌"; + } + return(prefix == null ? "" : prefix + ChatColor.RESET + " ") + progressBar + (suffix == null ? "" : ChatColor.RESET + " " + suffix); + } + } \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java index 5d5174f16..8484e58fd 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTime.java @@ -30,6 +30,12 @@ public class UtilTime SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_DAY); return sdf.format(cal.getTime()); } + + public static String date(long date) + { + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_DAY); + return sdf.format(date); + } public static String getDayOfMonthSuffix(final int n) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 7228b671e..cd62cf6fc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -128,7 +128,14 @@ public class CoreClientManager extends MiniPlugin if (client == null) { - client = new CoreClient(name); + if (Bukkit.getPlayer(name) != null) + { + client = new CoreClient(Bukkit.getPlayer(name)); + } + else + { + client = new CoreClient(name); + } } return client; @@ -285,6 +292,76 @@ public class CoreClientManager extends MiniPlugin }); } + public void loadClientByNameSync(final String playerName, final Runnable runnable) + { + try + { + ClientToken token = null; + Gson gson = new Gson(); + + // Fails if not in DB and if duplicate. + UUID uuid = loadUUIDFromDB(playerName); + + if (uuid == null) + { + try + { + uuid = UUIDFetcher.getUUIDOf(playerName); + } + catch (Exception exception) + { + System.out.println("Error fetching uuid from mojang : " + exception.getMessage()); + } + } + + String response = ""; + + if (uuid == null) + { + response = _repository.getClientByName(playerName); + } + else + { + response = _repository.getClientByUUID(uuid); + } + + token = gson.fromJson(response, ClientToken.class); + + CoreClient client = Add(playerName); + client.SetRank(Rank.valueOf(token.Rank), false); + client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName())); + + // JSON sql response + Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); + + if (client.getAccountId() > 0) + { + PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid); + + if (playerInfo != null) + { + playerInfo.setAccountId(client.getAccountId()); + PlayerCache.getInstance().addPlayer(playerInfo); + } + } + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() + { + public void run() + { + if (runnable != null) + runnable.run(); + } + }); + } + } + public boolean LoadClient(final CoreClient client, final UUID uuid, String ipAddress) { TimingManager.start(client.GetPlayerName() + " LoadClient Total."); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java index 8954b07c0..61ed15df6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java @@ -296,7 +296,7 @@ public class Chat extends MiniPlugin } } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOW) public void HandleChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java new file mode 100644 index 000000000..bd02855fe --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java @@ -0,0 +1,65 @@ +package mineplex.core.delayedtask; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.common.util.Callback; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class DelayedTask extends MiniClientPlugin +{ + public static DelayedTask Instance; + + public DelayedTask(JavaPlugin plugin) + { + super("Delayed Task", plugin); + } + + public static void Initialize(JavaPlugin plugin) + { + Instance = new DelayedTask(plugin); + } + + public void doDelay(Player player, String task, Callback end, Callback tick, Callback cancel, long wait, boolean allowMovement) + { + Get(player).insert(new Task(Get(player), task, end, tick, cancel, wait, allowMovement)); + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + Get(player).tick(); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + Get(event.getPlayer()).cleanup(); + } + + @EventHandler + public void onPlayerKick(PlayerKickEvent event) + { + Get(event.getPlayer()).cleanup(); + } + + @Override + protected DelayedTaskClient AddPlayer(String player) + { + return new DelayedTaskClient(Bukkit.getPlayer(player)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTaskClient.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTaskClient.java new file mode 100644 index 000000000..636b48294 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTaskClient.java @@ -0,0 +1,82 @@ +package mineplex.core.delayedtask; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.entity.Player; + +public class DelayedTaskClient +{ + public Map Tasks = new HashMap<>(); + + private Player _player; + + public DelayedTaskClient(Player player) + { + _player = player; + } + + public void insert(Task task) + { + Tasks.put(task.getName(), task); + } + + public long getTimeLeft(String task) + { + if (!Tasks.containsKey(task)) return -1; + + return getEndTime(task) - System.currentTimeMillis(); + } + + public long getEndTime(String task) + { + if (!Tasks.containsKey(task)) return -1; + + return Tasks.get(task).getEndTime(); + } + + public long getStartTime(String task) + { + if (!Tasks.containsKey(task)) return -1; + + return Tasks.get(task).getStartTime(); + } + + public void cleanup() + { + if (Tasks == null) + { + Tasks = new HashMap<>(); + } + + Tasks.clear(); + Tasks = null; + } + + public void cleanup(String task) + { + Tasks.remove(task); + } + + public void tick() + { + if (Tasks == null) + { + Tasks = new HashMap<>(); + } + + for (Task task : Tasks.values()) + { + if (task.getTick() != null) + { + task.tick(); + } + } + } + + public Player getPlayer() + { + return _player; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/Task.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/Task.java new file mode 100644 index 000000000..37a1204cd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/Task.java @@ -0,0 +1,95 @@ +package mineplex.core.delayedtask; + +import org.bukkit.Location; + +import mineplex.core.common.util.Callback; + +public class Task +{ + private DelayedTaskClient _client; + + private Callback _end; + private Callback _tick; + private Callback _cancel; + + private String _name; + + private long _startTime; + private long _endTime; + + private Location _startPos; + private boolean _allowMovement; + + public Task(DelayedTaskClient client, String task, Callback end, Callback tick, Callback cancel, long taskLength, boolean allowMovement) + { + _client = client; + + _name = task; + _end = end; + _tick = tick; + _cancel = cancel; + + _startPos = client.getPlayer().getLocation(); + + _allowMovement = allowMovement; + + _startTime = System.currentTimeMillis(); + _endTime = _startTime + taskLength; + } + + public String getName() + { + return _name; + } + + public Callback getEnd() + { + return _end; + } + + public Callback getTick() + { + return _tick; + } + + public long getEndTime() + { + return _endTime; + } + + public long getStartTime() + { + return _startTime; + } + + public void tick() + { + _tick.run(_client); + + if (!_allowMovement && _startPos.distance(_client.getPlayer().getLocation()) > 0.3) + { + if (_cancel != null) + { + _cancel.run(_client); + } + + if (_end != null) + { + _end.run(_client); + } + + _client.cleanup(_name); + return; + } + + if (System.currentTimeMillis() >= _endTime) + { + if (_end != null) + { + _end.run(_client); + } + + _client.cleanup(_name); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 813873d73..b23603f69 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -21,6 +21,7 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.donation.command.CoinCommand; import mineplex.core.donation.command.GemCommand; import mineplex.core.donation.command.GoldCommand; +import mineplex.core.donation.command.SetGoldCommand; import mineplex.core.donation.repository.DonationRepository; import mineplex.core.donation.repository.token.DonorTokenWrapper; import mineplex.core.server.util.TransactionResponse; @@ -49,6 +50,7 @@ public class DonationManager extends MiniDbClientPlugin addCommand(new GemCommand(this)); addCommand(new CoinCommand(this)); addCommand(new GoldCommand(this)); + addCommand(new SetGoldCommand(this)); } @EventHandler @@ -336,6 +338,35 @@ public class DonationManager extends MiniDbClientPlugin }, caller, name, accountId, amount); } + public void setGold(final Callback callback, final String caller, final String name, final int accountId, final int amount, final boolean updateTotal) + { + _repository.setGold(new Callback() + { + public void run(Boolean success) + { + if (success) + { + if (updateTotal) + { + Donor donor = Get(name); + + if (donor != null) + { + donor.setGold(amount); + } + } + } + else + { + System.out.println("SET GOLD FAILED..."); + } + + if (callback != null) + callback.run(success); + } + }, caller, name, accountId, amount); + } + public void RewardGoldLater(final String caller, final Player player, final int amount) { if (!_goldQueue.containsKey(player)) @@ -414,7 +445,7 @@ public class DonationManager extends MiniDbClientPlugin @Override public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException { - Get(playerName).addGold(_repository.retrieveDonorInfo(resultSet).getGold()); + Get(playerName).setGold(_repository.retrieveDonorInfo(resultSet).getGold()); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java index 7145b3dab..c6e583835 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java @@ -152,7 +152,11 @@ public class Donor public void addGold(int amount) { _gold = Math.max(0, _gold + amount); - + } + + public void setGold(int amount) + { + _gold = Math.max(0, amount); } public List getCoinTransactions() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/command/SetGoldCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/SetGoldCommand.java new file mode 100644 index 000000000..d477f5b8f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/SetGoldCommand.java @@ -0,0 +1,75 @@ +package mineplex.core.donation.command; + +import mineplex.core.account.CoreClient; +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.donation.DonationManager; + +import org.bukkit.entity.Player; + +public class SetGoldCommand extends CommandBase +{ + public SetGoldCommand(DonationManager plugin) + { + super(plugin, Rank.ADMIN, "setgold"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args == null || args.length < 2) + { + UtilPlayer.message(caller, F.main("Clans", "Error! Usage: " + F.elem("/setgold "))); + return; + } + + final String targetName = args[0]; + final String goldString = args[1]; + Player target = UtilPlayer.searchExact(targetName); + + try + { + if (target == null) + { + Plugin.getClientManager().loadClientByName(targetName, new Runnable() + { + public void run() + { + CoreClient client = Plugin.getClientManager().Get(targetName); + + if (client != null) + { + setGold(caller, null, targetName, client.getAccountId(), Integer.parseInt(goldString)); + } + else + { + UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName))); + } + } + }); + } + else + { + setGold(caller, target, target.getName(), Plugin.getClientManager().Get(target).getAccountId(), Integer.parseInt(goldString)); + } + } + catch (Exception e) + { + UtilPlayer.message(target, F.main("Clans", "You must provide a valid number in the gold parameter.")); + } + } + + private void setGold(final Player caller, final Player target, final String targetName, final int accountId, final int gold) + { + Plugin.setGold(new Callback() + { + public void run(Boolean completed) + { + UtilPlayer.message(caller, F.main("Gold", "You set " + F.name(targetName) + "'s Gold to " + F.elem(gold) + ".")); + } + }, caller.getName(), targetName, accountId, gold, true); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java index 98999dbf3..b30b30b92 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java @@ -31,6 +31,7 @@ public class DonationRepository extends RepositoryBase private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accountId, reason, coins) VALUES(?, ?, ?);"; private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE id = ?;"; private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ?;"; + private static String SET_ACCOUNT_GOLD = "UPDATE accounts SET gold = ? WHERE id = ?;"; private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE id = ? AND gems IS NULL AND coins IS NULL;"; private String _webAddress; @@ -198,6 +199,18 @@ public class DonationRepository extends RepositoryBase } }), "Error updating player gold amount in DonationRepository : "); } + + public void setGold(final Callback callback, final String giver, final String name, final int accountId, final int gold) + { + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + boolean success = executeUpdate(SET_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) > 0; + callback.run(success); + } + }), "Error updating player gold amount in DonationRepository : "); + } @Override protected void initialize() @@ -233,7 +246,7 @@ public class DonationRepository extends RepositoryBase while (resultSet.next()) { - donor.addGold(resultSet.getInt(1)); + donor.setGold(resultSet.getInt(1)); } return donor; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java index fa7070511..4f555ab3d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java @@ -173,6 +173,7 @@ public class ItemBuilder { for (String lore : lores) { + if (lore == null) continue; _lore.add(C.cGray + lore); } diff --git a/Plugins/Mineplex.Game.Clans/.classpath b/Plugins/Mineplex.Game.Clans/.classpath index 4a7e01944..4caf6a583 100644 --- a/Plugins/Mineplex.Game.Clans/.classpath +++ b/Plugins/Mineplex.Game.Clans/.classpath @@ -1,7 +1,7 @@ - + diff --git a/Plugins/Mineplex.Game.Clans/.settings/org.eclipse.jdt.core.prefs b/Plugins/Mineplex.Game.Clans/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..3a2153707 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index fd1887256..5d8be3794 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -13,6 +13,8 @@ import mineplex.core.antihack.AntiHack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.events.ServerShutdownEvent; +import mineplex.core.delayedtask.DelayedTask; import mineplex.core.donation.DonationManager; import mineplex.core.explosion.Explosion; import mineplex.core.friend.FriendManager; @@ -39,6 +41,7 @@ import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.visibility.VisibilityManager; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.ban.ClansBanManager; import mineplex.game.clans.items.GearManager; import mineplex.game.clans.shop.building.BuildingShop; import mineplex.game.clans.shop.farming.FarmingShop; @@ -50,7 +53,7 @@ import net.minecraft.server.v1_8_R3.MinecraftServer; public class Clans extends JavaPlugin { - public static final String VERSION = "0.17d"; + public static final String VERSION = "0.18"; private String WEB_CONFIG = "webServer"; // Modules @@ -77,6 +80,8 @@ public class Clans extends JavaPlugin ItemStackFactory.Initialize(this, false); + DelayedTask.Initialize(this); + Recharge.Initialize(this); VisibilityManager.Initialize(this); // new ProfileCacheManager(this); @@ -96,7 +101,9 @@ public class Clans extends JavaPlugin Teleport teleport = new Teleport(this, _clientManager); Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); - + + new ClansBanManager(this, _clientManager, _donationManager); + Punish punish = new Punish(this, webServerAddress, _clientManager); AntiHack.Initialize(this, punish, portal, preferenceManager, _clientManager); AntiHack.Instance.setKick(false); @@ -169,5 +176,7 @@ public class Clans extends JavaPlugin // Need to notify WorldEventManager of server shutdown, this seemed like // the only decent way to do it _clansManager.onDisable(); + + getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java index 5e82714fe..fac283def 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java @@ -20,19 +20,19 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilWorld; import mineplex.game.clans.clans.ClansUtility.ClanRelation; -import mineplex.game.clans.core.war.ClanWarData; -import net.minecraft.server.v1_8_R3.Material; +import mineplex.game.clans.clans.tntGenerator.TntGenerator; import mineplex.game.clans.core.repository.tokens.ClanAllianceToken; import mineplex.game.clans.core.repository.tokens.ClanMemberToken; import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken; import mineplex.game.clans.core.repository.tokens.ClanToken; - -import mineplex.game.clans.clans.tntGenerator.TntGenerator; import mineplex.game.clans.core.repository.tokens.ClanWarToken; +import mineplex.game.clans.core.war.ClanWarData; +import net.minecraft.server.v1_8_R3.Material; public class ClanInfo { @@ -374,6 +374,22 @@ public class ClanInfo player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 2f); } } + + public void inform(String top, String bottom, String ignore) + { + for (UUID cur : getMembers().keySet()) + { + Player player = UtilPlayer.searchExact(cur); + + if (player == null) + continue; + + if (player.getName().equals(ignore)) + continue; + + UtilTextMiddle.display(top, bottom, 20, 100, 20, player); + } + } public String getName() { @@ -507,6 +523,11 @@ public class ClanInfo public int getEnergy() { + if (_energy > getEnergyMax()) + { + _energy = getEnergyMax(); + } + return _energy; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java index dc0b837f7..1483b9949 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java @@ -38,8 +38,4 @@ public class ClansBlacklist return true; } - - public static void addBlacklist(String blacklist) { - BLACKLISTED_NAMES.add(blacklist); - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java index 9d06f8fa4..b848e7d28 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java @@ -532,8 +532,8 @@ public class ClansDataAccessLayer } // Log - // _manager.log("Added Claim for [" + name + "] at [" + chunk + "] by [" - // + player + "]."); + _manager.log("Added Claim for [" + name + "] at [" + chunk + "] by [" + + player + "]."); return true; } @@ -595,6 +595,8 @@ public class ClansDataAccessLayer // Log if (player != null) _manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [" + player + "]."); + else + _manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [NO ONE?!]."); // Bed Removal if (clan.getHome() != null && UtilWorld.chunkToStr(clan.getHome().getChunk()).equals(chunk)) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java index 7e8723996..46f5a3708 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java @@ -65,7 +65,9 @@ public class ClansDisplay extends MiniPlugin boolean safe = Clans.getClanUtility().isSafe(player); - UtilServer.getServer().getPluginManager().callEvent(new PlayerEnterTerritoryEvent(player, client.getOwner(), owner, owner.equals("Wilderness") ? false : Clans.getClanUtility().getClaim(player.getLocation()).isSafe(player.getLocation()))); + PlayerEnterTerritoryEvent event = new PlayerEnterTerritoryEvent(player, client.getOwner(), owner, owner.equals("Wilderness") ? false : Clans.getClanUtility().getClaim(player.getLocation()).isSafe(player.getLocation()), true); + + UtilServer.getServer().getPluginManager().callEvent(event); if (!client.isMapOn()) { @@ -87,13 +89,13 @@ public class ClansDisplay extends MiniPlugin if (showChange) { - displayOwner(player); - // Event + if (event.willSendMessage()) displayOwner(player); } } else { - displayOwner(player); + if (event.willSendMessage()) displayOwner(player); + displayMap(player); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index d51bb3f24..91e4d7f0b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -1,9 +1,9 @@ package mineplex.game.clans.clans; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TimeZone; @@ -28,9 +28,11 @@ import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; import org.bukkit.plugin.java.JavaPlugin; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + import mineplex.core.MiniClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; @@ -72,6 +74,7 @@ import mineplex.game.clans.clans.commands.ClansCommand; import mineplex.game.clans.clans.commands.ClansLoginManager; import mineplex.game.clans.clans.commands.KillCommand; import mineplex.game.clans.clans.commands.MapCommand; +import mineplex.game.clans.clans.commands.Meow; import mineplex.game.clans.clans.commands.RegionsCommand; import mineplex.game.clans.clans.data.PlayerClan; import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; @@ -79,6 +82,7 @@ import mineplex.game.clans.clans.gui.ClanShop; import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.map.ItemMapManager; import mineplex.game.clans.clans.observer.ObserverManager; +import mineplex.game.clans.clans.outpost.OutpostManager; import mineplex.game.clans.clans.playtime.Playtime; import mineplex.game.clans.clans.potato.PotatoManager; import mineplex.game.clans.clans.pvptimer.PvpTimer; @@ -203,6 +207,11 @@ public class ClansManager extends MiniClientPluginimplements IRelati { super("Clans Manager", plugin); + if (serverName.equals("GarboClans-1")) + { + addCommand(new Meow(new OutpostManager(this))); + } + _instance = this; _serverName = serverName; @@ -366,17 +375,26 @@ public class ClansManager extends MiniClientPluginimplements IRelati hologram.start(); } - // Disables beds from being crafted - Iterator it = _plugin.getServer().recipeIterator(); - Recipe recipe; - while (it.hasNext()) - { - recipe = it.next(); - if (recipe != null && recipe.getResult().getType() == Material.BED) - { - it.remove(); - } - } +// Iterator it = _plugin.getServer().recipeIterator(); +// Recipe recipe; +// while (it.hasNext()) +// { +// recipe = it.next(); +// if (recipe != null) +// { +// if (recipe.getResult().getType() == Material.SMOOTH_BRICK) +// { +// it.remove(); +// } +// } +// } +// +// final ShapedRecipe brrecipe = new ShapedRecipe(new ItemStack(Material.SMOOTH_BRICK, 1)); +// brrecipe.shape("XX", "XX", ""); +// brrecipe.setIngredient('X', Material.STONE); +// UtilServer.getServer().addRecipe(brrecipe); +// + Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict"); } @Override @@ -578,12 +596,33 @@ public class ClansManager extends MiniClientPluginimplements IRelati clanInfo.playerOnline(player); } - if (_clientManager.hasRank(player, Rank.DEVELOPER) || player.getName().equals("NewGarbo")) + if (_clientManager.hasRank(player, Rank.DEVELOPER) || player.getUniqueId().toString().equals("d8646a35-33a8-43c6-9e7c-2e871a6b86c9")) { player.setOp(true); } } + @EventHandler + public void disallowReplayMod(PlayerJoinEvent event) + { + // happens 20 ticks later because player channels don't + // seem to work immediately after joining. + runSyncLater(() -> { + ByteArrayDataOutput bado = ByteStreams.newDataOutput(); + + bado.writeUTF("no_xray"); + bado.writeBoolean(true); + + bado.writeUTF("no_noclip"); + bado.writeBoolean(true); + + bado.writeUTF("only_recording_player"); + bado.writeBoolean(true); + + event.getPlayer().sendPluginMessage(_plugin, "Replay|Restrict", bado.toByteArray()); + }, 20L); + } + @EventHandler public void denyBow(EntityShootBowEvent event) { @@ -610,14 +649,74 @@ public class ClansManager extends MiniClientPluginimplements IRelati } } - @EventHandler - public void handlePlayerChat(AsyncPlayerChatEvent event) + private void handleClanChat(AsyncPlayerChatEvent event, ClanInfo clan, String rank) { - if (event.isCancelled()) + for (Player cur : clan.getOnlinePlayers()) { + String message = _chat.getFilteredMessage(event.getPlayer(), event.getMessage()); + + UtilPlayer.message(cur, String.format(rank + C.cAqua + "%s " + C.cDAqua + "%s", event.getPlayer().getName(), message)); + } + } + + private void handleAllyChat(AsyncPlayerChatEvent event, ClanInfo clan, String rank) + { + List recipients = new ArrayList<>(); + + clan.getOnlinePlayers().forEach(recipients::add); + + for (String allyName : clan.getAllyMap().keySet()) + { + ClanInfo ally = _clanUtility.getClanByClanName(allyName); + if (ally == null) continue; + + ally.getOnlinePlayers().forEach(recipients::add); + } + + String message = _chat.getFilteredMessage(event.getPlayer(), event.getMessage()); + + recipients.forEach(p -> UtilPlayer.message(p, String.format(rank + C.cDGreen + clan.getName() + " " + C.cDGreen + "%s " + C.cGreen + "%s", event.getPlayer().getName(), message))); + + recipients.clear(); + } + + private void handleRegularChat(AsyncPlayerChatEvent event, ClanInfo clan, String rank) + { + if (clan == null) + { + UtilServer.broadcast(String.format(rank + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), event.getMessage())); return; } + List recipients = new ArrayList<>(); + + for (Player other : UtilServer.getPlayers()) + { + ClanInfo otherClan = _clanUtility.getClanByPlayer(other); + + if (otherClan == null) + { + recipients.add(other); + } + else + { + String message = _chat.getFilteredMessage(event.getPlayer(), event.getMessage()); + ClanRelation rel = _clanUtility.rel(clan, otherClan); + + other.sendMessage(rank + rel.getColor(true) + clan.getName() + " " + rel.getColor(false) + event.getPlayer().getName() + " " + C.cWhite + message); + } + } + + recipients.forEach(p -> p.sendMessage(String.format(rank + C.cGold + clan.getName() + " " + C.cYellow + "%s " + C.cWhite + "%s", event.getPlayer().getName(), event.getMessage()))); + + recipients.clear(); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void handlePlayerChat(AsyncPlayerChatEvent event) + { + event.setCancelled(true); + ClientClan client = Get(event.getPlayer()); if (client == null) @@ -634,91 +733,21 @@ public class ClansManager extends MiniClientPluginimplements IRelati if (client.isClanChat() && clan != null) { - event.setFormat(rank+ C.cAqua + "%1$s " + C.cDAqua + "%2$s"); - event.getRecipients().clear(); - - for (ClansPlayer cur : clan.getMembers().values()) - { - Player player = UtilPlayer.searchExact(cur.getUuid()); - - if (player == null) continue; - - event.getRecipients().add(player); - } + handleClanChat(event, clan, rank); } else if (client.isAllyChat() && clan != null) { - event.setFormat(rank+ C.cDGreen + clan.getName() + " " + C.cDGreen + "%1$s " + C.cGreen + "%2$s"); - event.getRecipients().clear(); - - for (ClansPlayer cur : clan.getMembers().values()) - { - Player player = UtilPlayer.searchExact(cur.getUuid()); - - if (player == null) continue; - - event.getRecipients().add(player); - } - - for (String allyName : clan.getAllyMap().keySet()) - { - ClanInfo ally = _clanUtility.getClanByClanName(allyName); - if (ally == null) continue; - - for (ClansPlayer cur : ally.getMembers().values()) - { - Player player = UtilPlayer.searchExact(cur.getUuid()); - - if (player == null) continue; - - event.getRecipients().add(player); - } - } + handleAllyChat(event, clan, rank); } else { - if (clan == null) - { - event.setFormat(rank + C.cYellow + "%1$s " + C.cWhite + "%2$s"); - System.out.println(_clientManager.Get(event.getPlayer()).GetRank().name() + " " + event.getPlayer().getName() + " " + event.getMessage()); - return; - } - - event.getRecipients().clear(); - event.setFormat(rank + C.cGold + clan.getName() + " " + C.cYellow + "%1$s " + C.cWhite + "%2$s"); - - for (Player other : UtilServer.getPlayers()) - { - ClanInfo otherClan = _clanUtility.getClanByPlayer(other); - - if (otherClan == null) - { - event.getRecipients().add(other); - } - else - { - String message = event.getMessage(); - message = _chat.getFilteredMessage(event.getPlayer(), message); - ClanRelation rel = _clanUtility.rel(clan, otherClan); - String formatted = rank + rel.getColor(true) + clan.getName() + " " + rel.getColor(false) + event.getPlayer().getName() + " " + C.cWhite + message; - other.sendMessage(formatted); - } - } + handleRegularChat(event, clan, rank); } System.out.println((clan == null ? "" : clan.getName()) + " " + _clientManager.Get(event.getPlayer()).GetRank().name() + " " + event.getPlayer().getName() + " " + event.getMessage()); } - @EventHandler - public void command(PlayerCommandPreprocessEvent event){ - if (event.getMessage().startsWith("/blacklist ")){ - String blacklist = event.getMessage().split(" ")[1]; - - ClansBlacklist.addBlacklist(blacklist); - } - } - public void messageClan(ClanInfo clan, String message) { for (Player player : clan.getOnlinePlayers()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java index 5b3e166ac..b18b93eff 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java @@ -8,7 +8,7 @@ public class ClansPlayer private UUID _uuid; private ClanRole _role; private boolean _online; - + public ClansPlayer(String playerName, UUID uuid, ClanRole role) { _playerName = playerName; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayerTasks.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayerTasks.java new file mode 100644 index 000000000..1cd37cb5a --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayerTasks.java @@ -0,0 +1,18 @@ +package mineplex.game.clans.clans; + +public enum ClansPlayerTasks +{ + FIRST_SESSION("Clans.FirstSession"); + + private String _id; + + ClansPlayerTasks(String id) + { + _id = id; + } + + public String id() + { + return _id; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBan.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBan.java new file mode 100644 index 000000000..dbc3c970f --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBan.java @@ -0,0 +1,85 @@ +package mineplex.game.clans.clans.ban; + +import java.sql.Timestamp; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilTime; + +public class ClansBan +{ + private int _id; + private int _accountId; + private String _reason; + private Timestamp _banTime; + private Timestamp _unbanTime; + private boolean _permanent; + private boolean _removed; + + public ClansBan(int id, int accountId, String reason, Timestamp banTime, Timestamp unbanTime, boolean permanent, boolean removed) + { + _id = id; + _accountId = accountId; + _reason = reason; + _banTime = banTime; + _unbanTime = unbanTime; + _permanent = permanent; + _removed = removed; + } + + public int getId() + { + return _id; + } + + public int getAccountId() + { + return _accountId; + } + + public String getReason() + { + return _reason; + } + + public Timestamp getBanTime() + { + return _banTime; + } + + public long getLength() + { + return _unbanTime.getTime() - _banTime.getTime(); + } + + public long getTimeLeft() + { + return Math.max(0, _unbanTime.getTime() - System.currentTimeMillis()); + } + + public Timestamp getUnbanTime() + { + return _unbanTime; + } + + public boolean isPermanent() + { + return _permanent; + } + + public String getBanTimeFormatted(boolean wording) + { + long time = getTimeLeft(); + + return time == -1 ? F.time("permanently") : (wording ? "for " : "") + F.time(UtilTime.MakeStr(time)); + } + + public boolean isRemoved() + { + return _removed; + } + + public boolean isActive() + { + return (isPermanent() || getTimeLeft() > 0) && !isRemoved(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanClient.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanClient.java new file mode 100644 index 000000000..57565214f --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanClient.java @@ -0,0 +1,86 @@ +package mineplex.game.clans.clans.ban; + +import java.util.List; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilTime; + +public class ClansBanClient +{ + public int AccountId; + public List Bans; + + public ClansBanClient(int accountId, List bans) + { + AccountId = accountId; + Bans = bans; + } + + public boolean isBanned() + { + for (ClansBan ban : Bans) + { + if (ban.isActive()) + { + return true; + } + } + + return false; + } + + public long getBanTime() + { + long time = 0; + + for (ClansBan ban : Bans) + { + if (!ban.isActive()) + { + continue; + } + + if (ban.isPermanent()) + { + return -1; + } + + time += ban.getTimeLeft(); + } + + return time; + } + + public String getBanTimeFormatted() + { + long time = getBanTime(); + + return time == -1 ? F.time("permanently") : "for " + F.time(UtilTime.MakeStr(time)); + } + + public ClansBan getLongestBan() + { + ClansBan longest = null; + + for (ClansBan ban : Bans) + { + if (!ban.isActive()) + { + continue; + } + + if (longest == null) + { + longest = ban; + continue; + } + + if (ban.getTimeLeft() > longest.getTimeLeft()) + { + longest = ban; + } + } + + return longest; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanManager.java new file mode 100644 index 000000000..1883da837 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanManager.java @@ -0,0 +1,210 @@ +package mineplex.game.clans.clans.ban; + +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.donation.DonationManager; +import mineplex.game.clans.clans.ban.commands.ClansBanCommand; +import mineplex.game.clans.clans.ban.commands.ClansBanListCommand; +import mineplex.game.clans.clans.ban.ui.ClansBanListShop; +import mineplex.game.clans.clans.ban.ui.ClansBanShop; + +public class ClansBanManager extends MiniPlugin +{ + private CoreClientManager _clientManager; + private ClansBanRepository _repository; + private Map _clients; + private Map _cache; + private ClansBanShop _shop; + private ClansBanListShop _shop2; + + public ClansBanManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super("Blacklist", plugin); + + _clientManager = clientManager; + + _repository = new ClansBanRepository(plugin, this); + + _clients = new HashMap<>(); + _cache = new HashMap<>(); + + _shop = new ClansBanShop(this, clientManager, donationManager); + _shop2 = new ClansBanListShop(this, clientManager, donationManager); + } + + @Override + public void addCommands() + { + addCommand(new ClansBanCommand(this)); + addCommand(new ClansBanListCommand(this)); + } + + public void ban(ClansBanClient client, String name, long time, String reason, Callback callback) + { + _repository.ban(client.AccountId, time, reason, time == -1); + + LoadClient(name, callback); + } + + public CoreClientManager getClientManager() + { + return _clientManager; + } + + public ClansBanRepository GetRepository() + { + return _repository; + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + LoadClient(event.getPlayer().getName(), client -> { + if (client.isBanned()) + { + String time = UtilTime.convertString(client.getLongestBan().getTimeLeft(), 0, TimeUnit.FIT); + + if (client.getLongestBan().isPermanent()) + time = "Permanent"; + + String reason = C.cRedB + "You are banned from Clans for " + time + + "\n" + C.cWhite + client.getLongestBan().getReason() + ; + + event.getPlayer().kickPlayer(reason); + } + else + { + UtilServer.broadcast(F.sys("Join", event.getPlayer().getName())); + } + }); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerQuit(PlayerQuitEvent event) + { + if (Get(event.getPlayer().getName()) == null) + { + return; + } + + if (Get(event.getPlayer().getName()).isBanned()) + { + event.setQuitMessage(null); + } + + UnloadClient(Get(event.getPlayer().getName())); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerKicked(PlayerKickEvent event) + { + if (Get(event.getPlayer().getName()) == null) + { + return; + } + + if (Get(event.getPlayer().getName()).isBanned()) + { + event.setLeaveMessage(null); + } + + UnloadClient(Get(event.getPlayer().getName())); + } + + public void UnloadClient(ClansBanClient client) + { + String name = ""; + + for (Entry entry : _clients.entrySet()) + { + if (entry.getValue().equals(client)) + { + name = entry.getKey(); + break; + } + } + + _clients.remove(name); + } + + public void LoadClient(final String name, Callback callback) + { + GetRepository().loadBans(name, client -> { + _clients.put(name, client); + System.out.println("> CLIENTS: " + _clients); + if (callback != null) callback.run(client); + }); + } + + public ClansBanClient Get(String name) + { + synchronized (this) + { + return _clients.get(name.toLowerCase()); + } + } + + public ClansBanShop getShop() + { + return _shop; + } + + public ClansBanListShop getShop2() + { + return _shop2; + } + + public void cache(Player player, String playerName) + { + _cache.put(player.getName(), playerName); + } + + public String getCachedName(Player player) + { + return _cache.get(player.getName()); + } + + public void clearCachedName(String name) + { + _cache.remove(name); + } + + public void unban(ClansBanClient target, ClansBan ban, String name, Callback callback) + { + if (target.AccountId != ban.getAccountId()) + { + return; + } + + _repository.removeBan(ban); + + LoadClient(name, callback); + } + + public void listRecordedNames(Callback> callback) + { + GetRepository().loadAll(callback); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java new file mode 100644 index 000000000..9860e8d5d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java @@ -0,0 +1,206 @@ +package mineplex.game.clans.clans.ban; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.NonFinalInteger; +import mineplex.core.database.DBPool; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.ResultSetCallable; +import mineplex.core.database.column.ColumnBoolean; +import mineplex.core.database.column.ColumnInt; +import mineplex.core.database.column.ColumnTimestamp; +import mineplex.core.database.column.ColumnVarChar; + +public class ClansBanRepository extends RepositoryBase +{ + private ClansBanManager _manager; + + private static final String GET_LONGEST_BAN = "SELECT * FROM clanBans WHERE (NOW() < unbanTime OR permanent=1) AND accountId = ? ORDER BY permanent DESC, unbanTime DESC LIMIT 1;"; + private static final String BAN_PLAYER = "INSERT INTO clanBans (accountId, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?);"; + private static final String REMOVE_BAN = "UPDATE clanBans SET removed = 1 WHERE id = ?;"; + private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE accountId = ?;"; + private static final String GET_ALL_ACCOUNTS = "SELECT DISTINCT accountId FROM clanBans;"; + + public ClansBanRepository(JavaPlugin plugin, ClansBanManager manager) + { + super(plugin, DBPool.getAccount()); + + _manager = manager; + } + + public void ban(int accountId, long time, String reason, boolean permanent) + { + executeInsert(BAN_PLAYER, null, + new ColumnInt("accountId", accountId), + new ColumnVarChar("reason", 128, reason), + new ColumnTimestamp("banTime", new Timestamp(System.currentTimeMillis())), + new ColumnTimestamp("unbanTime", new Timestamp(System.currentTimeMillis() + time)), + new ColumnBoolean("permanent", permanent), + new ColumnBoolean("removed", false) + ); + } + + public void loadBans(final String name, final Callback callback) + { + System.out.println(">> Attempting to load Clans Bans for \"" + name + "\""); + _manager.getClientManager().loadClientByName(name, new Runnable() { + public void run() + { + System.out.println("> Successfully loaded CoreClient"); + + executeQuery(GET_ALL_BANS, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + System.out.println("> Successfully executed query, result set object: " + resultSet); + + final List list = new ArrayList(); + + while (resultSet.next()) + { + int id = resultSet.getInt(1); + int accountId = resultSet.getInt(2); + String reason = resultSet.getString(3); + Timestamp banTime = resultSet.getTimestamp(4); + Timestamp unbanTime = resultSet.getTimestamp(5); + boolean permanent = resultSet.getBoolean(6); + boolean removed = resultSet.getBoolean(7); + + list.add(new ClansBan(id, accountId, reason, banTime, unbanTime, permanent, removed)); + } + + callback.run(new ClansBanClient(_manager.getClientManager().Get(name).getAccountId(), list)); + + System.out.println("> Successfully handled result"); + System.out.println(">> FINISH"); + } + }, new ColumnInt("accountId", _manager.getClientManager().Get(name).getAccountId())); + } + }); + } + + public void loadBansSync(final String name, final Callback callback) + { + System.out.println(">> Attempting to load Clans Bans for \"" + name + "\""); + _manager.getClientManager().loadClientByNameSync(name, new Runnable() { + public void run() + { + System.out.println("> Successfully loaded CoreClient"); + + executeQuery(GET_ALL_BANS, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + System.out.println("> Successfully executed query, result set object: " + resultSet); + + final List list = new ArrayList(); + + while (resultSet.next()) + { + int id = resultSet.getInt(1); + int accountId = resultSet.getInt(2); + String reason = resultSet.getString(3); + Timestamp banTime = resultSet.getTimestamp(4); + Timestamp unbanTime = resultSet.getTimestamp(5); + boolean permanent = resultSet.getBoolean(6); + boolean removed = resultSet.getBoolean(7); + + list.add(new ClansBan(id, accountId, reason, banTime, unbanTime, permanent, removed)); + } + + callback.run(new ClansBanClient(_manager.getClientManager().Get(name).getAccountId(), list)); + + System.out.println("> Successfully handled result"); + System.out.println(">> FINISH"); + } + }, new ColumnInt("accountId", _manager.getClientManager().Get(name).getAccountId())); + } + }); + } + + public void getLongestBan(final String name, final Callback callback) + { + if (callback == null) + { + return; + } + + _manager.getClientManager().loadClientByName(name, new Runnable(){ + public void run() + { + executeQuery(GET_LONGEST_BAN, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + int id = resultSet.getInt(1); + int accountId = resultSet.getInt(2); + String reason = resultSet.getString(3); + Timestamp banTime = resultSet.getTimestamp(4); + Timestamp unbanTime = resultSet.getTimestamp(5); + boolean permanent = resultSet.getBoolean(6); + boolean removed = resultSet.getBoolean(7); + + callback.run(new ClansBan(id, accountId, reason, banTime, unbanTime, permanent, removed)); + } + } + }, new ColumnInt("accountId", _manager.getClientManager().Get(name).getAccountId())); + } + }); + } + + public void loadAll(Callback> callback) + { + _manager.runAsync(() -> { + executeQuery(GET_ALL_ACCOUNTS, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + final List clients = new ArrayList<>(); + final NonFinalInteger resultsProcessed = new NonFinalInteger(); + int resultsFound = 0; + + while (resultSet.next()) + { + resultsFound++; + + int accountId = resultSet.getInt(0); + +// loadBans(_manager.getClientManager().) + + } + + System.out.println("Found: " + resultsFound + ", Processed: " + resultsProcessed); + } + }); + }); + } + + @Override + protected void initialize() + { + } + + @Override + protected void update() + { + } + + public void removeBan(ClansBan ban) + { + executeUpdate(REMOVE_BAN, new ColumnInt("id", ban.getId())); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java new file mode 100644 index 000000000..cc2768c13 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java @@ -0,0 +1,96 @@ +package mineplex.game.clans.clans.ban.commands; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.ban.ClansBanManager; + +public class ClansBanCommand extends CommandBase +{ + public ClansBanCommand(ClansBanManager plugin) + { + super(plugin, Rank.ADMIN, "cbans", "cb"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args == null || args.length < 1) + { + UtilPlayer.message(caller, C.cGold + "/cb - Bans the specified player for the specified amount of time"); + UtilPlayer.message(caller, C.cGold + "/cb - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)"); + } + else if (args.length == 1) + { + final String playerName = args[0]; + + Plugin.cache(caller, playerName); + Plugin.getShop().attemptShopOpen(caller); + } + else if (args.length > 2) + { + final String playerName = args[0]; + final float time; + final boolean permanent = args[1].startsWith("p"); + + if (!permanent) + { + try + { + time = Float.parseFloat(args[1]); + } + catch(NumberFormatException e) + { + UtilPlayer.message(caller, F.main("Clans", "You must provide a valid floating point number for the time (in days). e.g. " + F.elem("1.5") + ", " + F.elem("3.2") + ".")); + return; + } + } + else + { + //Required for compilation reasons + time = 0; + } + + String reason = args[2]; + + for (int i = 3; i < args.length; i++) + { + reason += " " + args[i]; + } + + final String finalReason = reason; + + //Match exact online first + Player target = UtilPlayer.searchExact(playerName); + if (target != null) + { + Plugin.LoadClient(playerName, client -> { + Plugin.ban(client, target.getName(), permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason, c -> { + UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + F.time(c.getBanTimeFormatted()) + ".")); + Bukkit.broadcastMessage(F.main("Clans", F.elem(playerName) + " is now banned " + F.time(c.getBanTimeFormatted()) + ".")); + Plugin.runSync(() -> target.kickPlayer(C.cRedB + "You have been banned from Clans " + c.getBanTimeFormatted() + ".")); + }); + }); + + return; + } + + Plugin.LoadClient(playerName, client -> { + Plugin.ban(client, playerName, permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason, c -> { + UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + c.getBanTimeFormatted() + ".")); + Bukkit.broadcastMessage(F.main("Clans", F.elem(playerName) + " is now banned " + F.time(c.getBanTimeFormatted()) + ".")); + }); + }); + } + else + { + UtilPlayer.message(caller, C.cGold + "/cp - Bans the specified player for the specified amount of time"); + UtilPlayer.message(caller, C.cGold + "/cp - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)"); + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanListCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanListCommand.java new file mode 100644 index 000000000..d4727bb4d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanListCommand.java @@ -0,0 +1,21 @@ +package mineplex.game.clans.clans.ban.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.game.clans.clans.ban.ClansBanManager; + +public class ClansBanListCommand extends CommandBase +{ + public ClansBanListCommand(ClansBanManager plugin) + { + super(plugin, Rank.ADMIN, "listbans"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + Plugin.getShop2().attemptShopOpen(caller); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanListPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanListPage.java new file mode 100644 index 000000000..22c58a21d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanListPage.java @@ -0,0 +1,32 @@ +package mineplex.game.clans.clans.ban.ui; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ban.ClansBanClient; +import mineplex.game.clans.clans.ban.ClansBanManager; + +public class ClansBanListPage extends ShopPageBase +{ + public ClansBanListPage(final ClansBanManager banManager, final ClansBanListShop shop, final CoreClientManager clientManager, final DonationManager donationManager, final String name, final Player player) + { + super(banManager, shop, clientManager, donationManager, name, player); + + buildPage(); + } + + protected void buildPage() + { + getPlugin().listRecordedNames(clients -> { + for (ClansBanClient client : clients) + { + } + }); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanListShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanListShop.java new file mode 100644 index 000000000..d3086d620 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanListShop.java @@ -0,0 +1,24 @@ +package mineplex.game.clans.clans.ban.ui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ban.ClansBanManager; + +public class ClansBanListShop extends ShopBase +{ + public ClansBanListShop(final ClansBanManager plugin, final CoreClientManager clientManager, final DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Clans Punish"); + } + + @Override + protected ShopPageBase> buildPagesFor(final Player player) + { + return new ClansBanListPage(getPlugin(), this, getClientManager(), getDonationManager(), "Clans Punish", player); + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanPage.java new file mode 100644 index 000000000..962ee17bf --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanPage.java @@ -0,0 +1,62 @@ +package mineplex.game.clans.clans.ban.ui; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilTime; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ban.ClansBan; +import mineplex.game.clans.clans.ban.ClansBanManager; + +public class ClansBanPage extends ShopPageBase +{ + public ClansBanPage(final ClansBanManager banManager, final ClansBanShop shop, final CoreClientManager clientManager, final DonationManager donationManager, final String name, final Player player) + { + super(banManager, shop, clientManager, donationManager, name, player); + + buildPage(); + } + + protected void buildPage() + { + String name = getPlugin().getCachedName(getPlayer()); + getPlugin().LoadClient(name, client -> { + int slot = 0; + + for (ClansBan ban : client.Bans) + { + ItemStack item = + new ItemBuilder(ban.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK) + .setTitle(ban.isActive() ? C.cGreenB + "Active" : C.cRedB + "Inactive") + + .addLore(" ") + .addLore("Date banned: " + C.cYellow + UtilTime.date(ban.getBanTime().getTime())) + .addLore("Time left: " + C.cYellow + (ban.isActive() ? ban.getBanTimeFormatted(false) : "None")) + .addLore("Permanent: " + C.cYellow + (ban.isPermanent() ? "Yes" : "No")) + .addLore(C.cGray + "Reason: " + C.cYellow + ban.getReason(), 16) + .addLore("Is Disabled: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No")) + .addLore(!ban.isActive() ? null : C.cDAqua + "Left-Click to disable ban") + + .build(); + + if (ban.isActive()) + { + UtilInv.addDullEnchantment(item); + } + + addButton(slot++, item, (player, click) -> { + if (ban.isActive()) + { + getPlugin().unban(client, ban, name, c -> refresh()); + } + }); + } + }); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanShop.java new file mode 100644 index 000000000..f24554858 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ui/ClansBanShop.java @@ -0,0 +1,24 @@ +package mineplex.game.clans.clans.ban.ui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ban.ClansBanManager; + +public class ClansBanShop extends ShopBase +{ + public ClansBanShop(final ClansBanManager plugin, final CoreClientManager clientManager, final DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Clans Punish"); + } + + @Override + protected ShopPageBase> buildPagesFor(final Player player) + { + return new ClansBanPage(getPlugin(), this, getClientManager(), getDonationManager(), "Clans Punish", player); + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 3fda15789..28d32055f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -15,9 +15,12 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilInput; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilWorld; +import mineplex.core.delayedtask.DelayedTask; +import mineplex.core.delayedtask.DelayedTaskClient; import mineplex.core.recharge.Recharge; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanRole; @@ -27,14 +30,11 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClientClan; import mineplex.game.clans.clans.event.ClanJoinEvent; import mineplex.game.clans.clans.event.ClansCommandExecutedEvent; -import mineplex.game.clans.tutorials.Tutorial; -import mineplex.game.clans.tutorials.TutorialManager; import net.minecraft.server.v1_8_R3.EnumDirection; public class ClansCommand extends CommandBase { private ClansManager _manager; - public ClansCommand(ClansManager plugin) { super(plugin, Rank.ALL, "c", "clan", "clans", "factions"); @@ -127,7 +127,7 @@ public class ClansCommand extends CommandBase private void forceJoin(Player caller, String[] args) { - if (!Plugin.getClientManager().hasRank(caller, Rank.ADMIN) && !caller.getName().equals("NewGarbo")) + if (!Plugin.getClientManager().hasRank(caller, Rank.ADMIN) && !caller.getUniqueId().toString().equals("d8646a35-33a8-43c6-9e7c-2e871a6b86c9")) { _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This requires ADMIN+ permission.")); return; @@ -741,7 +741,7 @@ public class ClansCommand extends CommandBase Plugin.getItemMapManager().setMap(caller); } - public void home(Player caller, String[] args) + public void home(final Player caller, String[] args) { if (args.length > 1) { @@ -752,7 +752,7 @@ public class ClansCommand extends CommandBase } } - ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); + final ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); if (clan == null) { @@ -772,18 +772,6 @@ public class ClansCommand extends CommandBase return; } - if (!Plugin.getClanUtility().isSafe(caller.getLocation())) - { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can only use Clan Home from Spawn.")); - return; - } - - if (!Plugin.getClanUtility().isSpecial(caller.getLocation(), "Spawn")) - { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can only use Clan Home from Spawn.")); - return; - } - Location home = clan.getHome(); if (!(home.getBlock().getType().equals(Material.BED_BLOCK) && home.add(0, 1, 0).getBlock().getType().equals(Material.AIR)) && home.add(0, 2, 0).getBlock().getType().equals(Material.AIR)) @@ -802,14 +790,31 @@ public class ClansCommand extends CommandBase * } */ - // if (!Recharge.Instance.use(caller, "Clans Teleport", "Clans - // Teleport", 300000, true, false, false, false)) return; + if (!Recharge.Instance.use(caller, "Home Teleport", 5 * 60 * 1000, true, false)) + { + return; + } - // Do - Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0)); - - // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + ".")); + DelayedTask.Instance.doDelay(caller, "Home Teleport", new Callback() { + public void run(DelayedTaskClient player) + { + // Do + Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0)); + + // Inform + _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + ".")); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilTextMiddle.display("", "Teleporting to Clan Home in " + F.elem(UtilTime.MakeStr(Math.max(0, client.getTimeLeft("Home Teleport")))), 0, 5, 0); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement.")); + } + }, (Plugin.getClanUtility().getClaim(caller.getLocation()) != null ? 30 : 20) * 1000, false); } public void homeSet(Player caller) @@ -881,7 +886,9 @@ public class ClansCommand extends CommandBase } public void infoClan(Player caller, String search) - {System.out.println(search); + { + System.out.println(search); + if (search == null) { _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter.")); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java index 1267209fb..1b8575083 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java @@ -41,8 +41,8 @@ public class ClansLoginManager extends MiniPlugin implements ILoginProcessor { if (_queue.contains(event.getPlayer().getName()) && !event.getPlayer().isOp()) { - event.setKickMessage("This is not your Clans home server"); - event.setResult(PlayerLoginEvent.Result.KICK_OTHER); +// event.setKickMessage("This is not your Clans home server"); +// event.setResult(PlayerLoginEvent.Result.KICK_OTHER); } _queue.remove(event.getPlayer().getName()); @@ -50,18 +50,18 @@ public class ClansLoginManager extends MiniPlugin implements ILoginProcessor private void kickPlayer(final String playerName, final String homeServer) { - runSyncLater(new Runnable() - { - @Override - public void run() - { - Player player = UtilPlayer.searchExact(playerName); - if (player != null && player.isOnline() && !player.isOp()) - { - player.kickPlayer("This is not your home server. To play clans, connect to " + homeServer); - } - } - }, 20); +// runSyncLater(new Runnable() +// { +// @Override +// public void run() +// { +// Player player = UtilPlayer.searchExact(playerName); +// if (player != null && player.isOnline() && !player.isOp()) +// { +// player.kickPlayer("This is not your home server. To play clans, connect to " + homeServer); +// } +// } +// }, 20); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/Meow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/Meow.java new file mode 100644 index 000000000..b6bc54b64 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/Meow.java @@ -0,0 +1,22 @@ +package mineplex.game.clans.clans.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.game.clans.clans.outpost.Outpost; +import mineplex.game.clans.clans.outpost.OutpostManager; + +public class Meow extends CommandBase +{ + public Meow(OutpostManager plugin) + { + super(plugin, Rank.ALL, "meow"); + } + + @Override + public void Execute(Player caller, String[] args) + { + caller.getInventory().addItem(Outpost.OUTPOST_ITEM); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java index 7a8d6aa41..80e9a4a4d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java @@ -12,9 +12,11 @@ public class PlayerEnterTerritoryEvent extends Event private String _lastTerritory; private Player _player; + private boolean _sendMessage; + private boolean _safe; - public PlayerEnterTerritoryEvent(Player player, String lastTerritory, String newTerritory, boolean safe) + public PlayerEnterTerritoryEvent(Player player, String lastTerritory, String newTerritory, boolean safe, boolean sendMessage) { _player = player; _lastTerritory = lastTerritory; @@ -27,6 +29,16 @@ public class PlayerEnterTerritoryEvent extends Event return _player; } + public boolean willSendMessage() + { + return _sendMessage; + } + + public void setSendMessage(boolean flag) + { + _sendMessage = flag; + } + public String getLastTerritory() { return _lastTerritory; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java index bc6240df7..dd417956c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java @@ -31,7 +31,7 @@ public class ClanWhoPage extends ClanPageBase public ClanWhoPage(ClansManager plugin, ClanShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, ClanInfo lookupClan, boolean showBackButton) { - super(plugin, shop, clientManager, donationManager, lookupClan.getName(), player, 36); + super(plugin, shop, clientManager, donationManager, lookupClan.getName(), player, 45); _lookupClan = lookupClan; _showBackButton = showBackButton; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java new file mode 100644 index 000000000..50a461601 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java @@ -0,0 +1,451 @@ +package mineplex.game.clans.clans.outpost; + +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.function.Predicate; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.FallingBlock; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.ColorFader; +import mineplex.core.common.util.F; +import mineplex.core.common.util.LoopIterator; +import mineplex.core.common.util.NonFinalInteger; +import mineplex.core.common.util.RGBData; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilColor; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.hologram.Hologram; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansBlacklist; +import mineplex.game.clans.core.repository.ClanTerritory; +import net.minecraft.server.v1_8_R3.AxisAlignedBB; + +public class Outpost implements Listener +{ + protected static final long MAX_LIFETIME = 5 * 60 * 1000; // 30 minutes + public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore("Seems to be a mystical contraption of some sort!").build(); + public static final byte OUTPOST_BLOCK_DATA = (byte) 137; + + private OutpostManager _host; + + private ClanInfo _clan; + + private Location _startCorner; + private Location _origin; + private Location _endCorner; + + private Location _forceFieldStart; + private Location _forceFieldEnd; + + private Location _core; + + private LinkedHashMap _blocks; + private LinkedHashMap _buildQueue; + + private OutpostType _type; + private OutpostState _state; + + private Hologram _preHologram; + private Hologram _preHologram2; + + private LoopIterator _circleStages; + private LoopIterator _reverseCircleStages; + + private ColorFader _fader = new ColorFader(30, UtilColor.hexToRgb(0x00A296), UtilColor.hexToRgb(0x29E6B6)); + + private long _spawnTime; + + public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) + { + _host = host; + + _clan = clan; + + _startCorner = location.clone().subtract(type._size, 1, type._size); + _endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9); + + _forceFieldStart = _startCorner.clone().subtract(3, 0, 3); + _forceFieldEnd = _endCorner.clone().add(3, 0, 3); + + _origin = location.clone(); + + _type = type; + + _spawnTime = System.currentTimeMillis(); + + _core = _type.getCoreLocation(_origin); + + _preHologram = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_clan.getName()) + C.cWhite + "'s Outpost block"); + _preHologram2 = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); + + _preHologram.start(); + _preHologram2.start(); + + _state = OutpostState.AWAITING; + } + + private void cleanup() + { + _blocks = null; + + if (_preHologram != null) _preHologram.stop(); + if (_preHologram2 != null) _preHologram2.stop(); + + _preHologram = null; + _preHologram2 = null; + + _state = OutpostState.DEAD; + + _host.queueForRemoval(_clan.getName()); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + if (getState() != OutpostState.AWAITING) + { + return; + } + + if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) + { + return; + } + + if (getLifetime() <= 2000) + { + return; + } + + if (!_clan.equals(_clan.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!")); + return; + } + + if (event.getClickedBlock() != null && _origin.equals(event.getClickedBlock().getLocation())) + { + if (event.getClickedBlock().getType().equals(Material.NETHERRACK)) + { + _origin.getBlock().setType(Material.AIR); + beginConstruction(); + } + } + } + + @EventHandler + public void onBlockDamage(BlockDamageEvent event) + { + if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_clan.getName()) + "'s Outpost!")); + + _core.getBlock().setType(Material.AIR); + + _clan.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _clan.getOnlinePlayersArray()); + + if (getState() == OutpostState.AWAITING) + { + cleanup(); + } + else + { + kill(); + } + + event.setCancelled(true); + } + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + if (getState() == OutpostState.AWAITING && event.getBlock().getLocation().equals(_origin)) + { + _origin.getBlock().setType(Material.AIR); + _origin.getWorld().dropItem(_origin, OUTPOST_ITEM); + _clan.inform("Your Outpost block has been destroyed.", null); + cleanup(); + event.setCancelled(true); + return; + } + + _blocks.values().stream().filter(event.getBlock().getLocation()::equals).forEach(block -> { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks in Outposts.")); + event.setCancelled(true); + }); + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) + { + if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner, _endCorner)) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks in Outposts.")); + event.setCancelled(true); + } + } + + protected void update() + { + if (_state == OutpostState.AWAITING) + { + if (getLifetime() > 60000) + { + _origin.getBlock().setType(Material.AIR); + _clan.inform("You have lost your Outpost block, as no one activated it fast enough!", null); + cleanup(); + return; + } + + _preHologram2.setText(UtilText.getProgress(null, UtilMath.clamp(getLifetime(), 0., 60000.) / 60000., null, true)); + + RGBData color = UtilColor.RgbLightBlue; + + for (int x = -_type._size; x <= _type._size; x++) + { + for (int z = -_type._size; z <= _type._size; z++) + { + if (x == -_type._size || x == _type._size || z == -_type._size || z == _type._size) + { + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, UtilBlock.getHighest(_origin.getWorld(), _origin.clone().add(x + .5, .1, z + .5).getBlockX(), _origin.clone().add(x + .5, .1, z + .5).getBlockZ()).getLocation().add(0.5, 0, 0.5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL); + } + } + } + + return; + } + + if (_state == OutpostState.CONSTRUCTING) + { + if (_buildQueue.isEmpty()) + { + _state = OutpostState.LIVE; + + return; + } + else + { + Iterator iterator = _buildQueue.keySet().iterator(); + + if (iterator.hasNext()) + { + _buildQueue.remove(iterator.next()).set(); + } + } + + // Forcefield + RGBData color = UtilColor.RgbLightBlue; + + for (int x = -_type._size; x <= _type._size; x++) + { + for (int z = -_type._size; z <= _type._size; z++) + { + if (x == -_type._size || x == _type._size || z == -_type._size || z == _type._size) + { + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _origin.clone().add(x + .5, .1, z + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL); + } + } + } + } + + RGBData next = _fader.next(); + + { + RGBData color = _state == OutpostState.LIVE ? next : UtilColor.RgbRed; + + Vector nextCircleStage = _circleStages.next(); + + double circleX = nextCircleStage.getX(); + double circleZ = nextCircleStage.getZ(); + + UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 5.f, 0, ViewDist.NORMAL); + } + + { + RGBData color = _state == OutpostState.LIVE ? next : UtilColor.RgbRed; + + Vector nextCircleStage = _reverseCircleStages.next(); + + double circleX = nextCircleStage.getX(); + double circleZ = nextCircleStage.getZ(); + + UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 5.f, 0, ViewDist.NORMAL); + } + } + + @EventHandler + public void forcefield(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST && getState() == OutpostState.CONSTRUCTING) + { + return; + } + + UtilServer.getPlayersCollection().stream() + .filter(player -> !_clan.isMember(player)) + .filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd)) + .forEach(player -> { + UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), 1, true, 0.8, 0, 1.1, true); + UtilPlayer.message(player, F.main("Clans", "This Outpost is still under construction!")); + player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f); + }); + } + + public void beginConstruction() + { + // Cleanup pre-Outpost stuff + _preHologram.stop(); + _preHologram2.stop(); + + _preHologram = null; + _preHologram = null; + + _state = OutpostState.CONSTRUCTING; + _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _clan.Clans)); + + _clan.inform("Siege", "Your Outpost is now being constructed.", null); + + _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); + + List reverse = circleAround(new Vector(0., 0., 0.), 40, .6d); + Collections.reverse(reverse); + _reverseCircleStages = new LoopIterator(reverse); + + //Inform nearby Clans + for (int chunkX = -3; chunkX < 3; chunkX++) + { + for (int chunkZ = -3; chunkZ < 3; chunkZ++) + { + ClanTerritory territory = _clan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); + + if (territory != null && ClansBlacklist.isValidClanName(territory.Owner)) + { + ClanInfo clan = _clan.Clans.getClanUtility().getClanByClanName(territory.Owner); + + clan.inform("A siege has begun near your territory!", null); + UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray()); + } + } + } + } + + private List circleAround(Vector origin, int points, double radius) + { + List list = new LinkedList<>(); + + double slice = 2 * Math.PI / points; + + for (int point = 0; point < points; point++) + { + double angle = slice * point; + list.add(new Vector(origin.getX() + radius * Math.cos(angle), 0, origin.getZ() + radius * Math.sin(angle))); + } + + return list; + } + + public void instakill() + { + _blocks.values().forEach(OutpostBlock::restore); + + cleanup(); + } + + public void kill() + { + _state = OutpostState.DESTRUCTING; + + NonFinalInteger wait = new NonFinalInteger(0); + + _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() || UtilMath.random.nextBoolean() || UtilMath.random.nextBoolean() || UtilMath.random.nextBoolean()).forEach(block -> + _host.runSyncLater(() -> { + UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, block._loc, new Vector(0,0,0), 1f, 1, ViewDist.NORMAL); + _origin.getWorld().playSound(block._loc, Sound.EXPLODE, 1.0f, 1.0f); + }, wait.add(4 + UtilMath.random.nextInt(4)).get()) + ); + + _host.runSyncLater(() -> { + _blocks.values().forEach(block -> { + Material mat = Material.getMaterial(block._id); + + if (UtilItem.isTranslucent(mat)) + { + block.restore(); + return; + } + + FallingBlock fall = block._loc.getWorld().spawnFallingBlock(block._loc, block._id, block._data); + fall.setDropItem(false); + Vector vec = UtilAlg.getTrajectory(fall.getLocation(), getExactMiddle()); + + UtilAction.velocity(fall, vec, 1, false, 0, 0.6, 10, false); + + fall.setMetadata("ClansOutpost", new FixedMetadataValue(_clan.Clans.getPlugin(), _clan.getName())); + + block.restore(); + }); + + cleanup(); + }, wait.get() + 5L); + + _clan.inform("Your Clan's Outpost has been destroyed.", null); + } + + public ClanInfo getClan() + { + return _clan; + } + + public long getLifetime() + { + return System.currentTimeMillis() - _spawnTime; + } + + public AxisAlignedBB getBounds() + { + return UtilAlg.toBoundingBox(_startCorner, _endCorner); + } + + public Location getExactMiddle() + { + return UtilAlg.getMidpoint(_startCorner, _endCorner); + } + + public OutpostState getState() + { + return _state; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlock.java new file mode 100644 index 000000000..cf5b4dac9 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlock.java @@ -0,0 +1,57 @@ +package mineplex.game.clans.clans.outpost; + +import java.util.Map; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.BlockState; + +import mineplex.core.common.util.UtilWorld; + +public class OutpostBlock +{ + protected Location _loc; + protected int _id; + protected byte _data; + + protected int _originalId; + protected byte _originalData; + + public OutpostBlock(Map blocks, Location loc, int id, byte data) + { + _loc = loc; + _id = id; + _data = data; + + String locStr = UtilWorld.locToStr(loc); + + if (blocks.containsKey(locStr)) + { + _originalId = blocks.get(locStr)._originalId; + _originalData = blocks.get(locStr)._originalData; + } + else + { + _originalId = _loc.getBlock().getTypeId(); + _originalData = _loc.getBlock().getData(); + } + } + + public void set() + { + _loc.getBlock().setTypeIdAndData(_id, _data, false); + if (_id != 0) + { + _loc.getWorld().playEffect(_loc, Effect.STEP_SOUND, Material.getMaterial(_id), 10); + } + } + + public void restore() + { + BlockState state = _loc.getBlock().getState(); + state.setTypeId(_originalId); + state.setRawData(_originalData); + state.update(true, false); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java new file mode 100644 index 000000000..aa97fb266 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java @@ -0,0 +1,218 @@ +package mineplex.game.clans.clans.outpost; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.events.ServerShutdownEvent; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; + +public class OutpostManager extends MiniPlugin +{ + private ClansManager _clansManager; + + private Map _outposts = new HashMap<>(); + + private List _removalQueue; + + public OutpostManager(ClansManager clansManager) + { + super("Outpost Manager", clansManager.getPlugin()); + + _clansManager = clansManager; + + _removalQueue = new ArrayList<>(); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlaceBlock(BlockPlaceEvent event) + { + if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM)) + { + if (!Recharge.Instance.use(event.getPlayer(), "Place Outpost", 10000, true, false)) + { + event.setCancelled(true); + return; + } + + if (Spawn(event.getPlayer(), event.getBlock().getLocation(), OutpostType.ORIGINAL_CLANS)) + { + event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA); + } + else + { + event.setCancelled(true); + } + } + } + + public boolean Spawn(Player player, Location location, OutpostType type) + { + if (!_clansManager.isInClan(player)) + { + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place an Outpost.")); + return false; + } + + if (location.getBlockY() < 10) + { + UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this deep.")); + return false; + } + + ClanInfo clan = _clansManager.getClan(player); + + if (UtilItem.isBoundless(location.clone().subtract(0, 1, 0).getBlock().getType())) + { + UtilPlayer.message(player, F.main("Clans", "An Outpost must not be placed floating.")); + return false; + } + + if (Get(clan) != null) + { + UtilPlayer.message(player, F.main("Clans", "Your clan already has an outpost")); + return false; + } + + if (_clansManager.getClanUtility().getClaim(location) != null) + { + UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed in the Wilderness.")); + return false; + } + + for (Outpost outpost : _outposts.values()) + { + if (UtilMath.offset(location, outpost.getExactMiddle()) < 14) + { + UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost near other Outposts.")); + return false; + } + } + + for (int x = -type._size; x < type._size; x++) + { + for (int y = -1; y < type._ySize; y++) + { + for (int z = -type._size; z < type._size; z++) + { + Location loc = location.clone().add(x, y, z); + + if (_clansManager.getClanUtility().isClaimed(loc)) + { + UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost where it may intersect with claimed territory.")); + return false; + } + + if (UtilBlock.airFoliage(location.clone().add(x, -1, z).getBlock())) + { + UtilPlayer.message(player, F.main("Clans", "An Outpost cannot be placed floating.")); + return false; + } + } + } + } + + _outposts.put(clan.getName(), new Outpost(this, clan, location, type)); + + _plugin.getServer().getPluginManager().registerEvents(_outposts.get(clan.getName()), _plugin); + + return true; + } + + @EventHandler + public void onBlockFall(EntityChangeBlockEvent event) + { + if (event.getEntity().hasMetadata("ClansOutpost")) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onServerShutdown(ServerShutdownEvent event) + { + for (Outpost outpost : _outposts.values()) + { + outpost.instakill(); + } + } + + @EventHandler + public void onClaim(PlayerClaimTerritoryEvent event) + { + for (Outpost outpost : _outposts.values()) + { + if (outpost.getBounds().b(UtilAlg.toBoundingBox(event.getClaimedChunk().getBlock(0, 0, 0).getLocation(), event.getClaimedChunk().getBlock(15, 254, 15).getLocation()))) + { + event.setCancelled(true); + UtilPlayer.message(event.getClaimer(), F.main("Clans", "You cannot claim this territory as it overlaps with " + F.elem(outpost.getClan().getName()) + "'s Outpost.")); + break; + } + } + } + + @EventHandler + public void update(UpdateEvent event) + { + for (Outpost outpost : _outposts.values()) + { + if (outpost.getState() != OutpostState.DEAD) + { + if (outpost.getState() == OutpostState.CONSTRUCTING ? event.getType() == UpdateType.FASTER : event.getType() == UpdateType.TICK) + { + outpost.update(); + } + } + } + + if (event.getType() == UpdateType.FASTER) + { + if (!_removalQueue.isEmpty()) + { + HandlerList.unregisterAll(_outposts.remove(_removalQueue.remove(0))); + } + } + + if (event.getType() == UpdateType.TWOSEC) + { + for (Outpost outpost : _outposts.values()) + { + if (outpost.getState() == OutpostState.LIVE && outpost.getLifetime() > Outpost.MAX_LIFETIME) + { + outpost.kill(); + } + } + } + } + + public Outpost Get(ClanInfo clan) + { + return _outposts.get(clan.getName().toLowerCase()); + } + + public void queueForRemoval(String name) + { + _removalQueue.add(name); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostState.java new file mode 100644 index 000000000..310e9bb59 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostState.java @@ -0,0 +1,10 @@ +package mineplex.game.clans.clans.outpost; + +public enum OutpostState +{ + AWAITING, + CONSTRUCTING, + LIVE, + DESTRUCTING, + DEAD; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java new file mode 100644 index 000000000..bb88bea1b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java @@ -0,0 +1,225 @@ +package mineplex.game.clans.clans.outpost; + +import java.util.LinkedHashMap; + +import org.bukkit.Location; +import org.bukkit.Material; + +import mineplex.core.common.util.UtilWorld; +import mineplex.game.clans.clans.ClansManager; + +public enum OutpostType +{ + ORIGINAL_CLANS(3, 6) { + public LinkedHashMap createBuildQueue(Location location, ClansManager clans) + { + LinkedHashMap build = new LinkedHashMap<>(); + + for (int y = -1; y <= _ySize; y++) + { + for (int x = -_size; x <= _size; x++) + { + for (int z = -_size; z <= _size; z++) + { + Location loc = new Location(location.getWorld(), location.getX()+x, location.getY()+y, location.getZ()+z); + + if (clans.getClanUtility().isClaimed(loc)) + { + continue; + } + + boolean added = false; + + //Floor + if (y == -1 && Math.abs(x) <= _size-1 && Math.abs(z) <= _size-1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 98, (byte)0)); + added = true; + } + + //Walls + if (Math.abs(x) == _size || Math.abs(z) == _size) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 98, (byte)0)); + added = true; + } + + //Roof + if (y == 5 && Math.abs(x) <= _size-1 && Math.abs(z) <= _size-1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 44, (byte)13)); + added = true; + } + + //Clear + if (!added) + { + if (loc.getBlock().getTypeId() != 0) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 0, (byte) 0)); + } + } + } + } + } + + for (int y= -1; y <= _ySize; y++) + { + for (int x = -_size; x <= _size; x++) + { + for (int z = -_size; z <= _size; z++) + { + Location loc = new Location(location.getWorld(), location.getX()+x, location.getY()+y, location.getZ()+z); + + if (clans.getClanUtility().isClaimed(loc)) + { + continue; + } + + //Doors + if (y == 0 || y == 1) + { + if (x == 0 && z == _size) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 71, (byte)(y * 8 + 2 + 4))); + } + + if (x == 0 && z == -_size) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 71, (byte)(y * 8 + 4))); + } + + if (x == _size && z == 0) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 71, (byte)(y * 8 + 3 + 4))); + } + + if (x == -_size && z == 0) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 71, (byte)(y * 8 + 1 + 4))); + } + } + + //Platform + if (y == 2) + { + if (Math.abs(x) == _size-1 && Math.abs(z) < _size) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 44, (byte)13)); + } + + if (Math.abs(z) == _size-1 && Math.abs(x) < _size) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 44, (byte)13)); + } + } + + //Windows + if (y == 4) + { + if (Math.abs(x) == _size && Math.abs(z) < _size-1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 0, (byte)0)); + } + + if (Math.abs(z) == _size && Math.abs(x) < _size-1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 0, (byte)0)); + } + } + + //Ladders + if (y >= 0 && y < 3) + { + if (x == _size-1 && z == _size-1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 65, (byte)2)); + } + + if (x == (-_size)+1 && z == (-_size)+1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 65, (byte)3)); + } + } + + //Chests + if (y == 0) + { + if (x == _size-1 && z == (-_size)+1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 54, (byte)0)); + } + + if (x == (-_size)+1 && z == _size-1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 54, (byte)0)); + } + + if (x == _size-2 && z == (-_size)+1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 54, (byte)0)); + } + + if (x == (-_size)+2 && z == _size-1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 54, (byte)0)); + } + } + + //Beacon Floor + if (y == -1) + { + if (Math.abs(x) <= 1 && Math.abs(z) <= 1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 42, (byte)0)); + } + } + + //Beacon Roof + if (y == 5) + { + if (Math.abs(x) == 1 && Math.abs(z) <= 1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 98, (byte)0)); + } + + if (Math.abs(z) == 1 && Math.abs(x) <= 1) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 98, (byte)0)); + } + } + + //Beacon Glass + if (y == 5 && x == 0 && z == 0) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, 20, (byte)0)); + } + } + } + } + + //Core + build.put(UtilWorld.locToStr(getCoreLocation(location)), new OutpostBlock(build, getCoreLocation(location), Material.DIAMOND_BLOCK.getId(), (byte)0)); + + return build; + } + + public Location getCoreLocation(Location location) + { + return location.clone().subtract(0, 1, 0); + } + }; + + protected int _size; + protected int _ySize; + + OutpostType(int size, int ySize) + { + _size = size; + _ySize = ySize; + } + + public abstract LinkedHashMap createBuildQueue(Location location, ClansManager clans); + + public abstract Location getCoreLocation(Location location); +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/PlayingClient.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/PlayingClient.java index fd68d2949..dcbad45bd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/PlayingClient.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/PlayingClient.java @@ -1,13 +1,18 @@ package mineplex.game.clans.clans.playtime; +import org.bukkit.entity.Player; + +import mineplex.core.task.TaskManager; +import mineplex.game.clans.clans.ClansPlayerTasks; + public class PlayingClient { public long StartTime; public boolean FirstSession; - public PlayingClient(boolean first) + public PlayingClient(Player player, TaskManager taskManager) { StartTime = System.currentTimeMillis(); - FirstSession = first; + FirstSession = taskManager.hasCompletedTask(player, ClansPlayerTasks.FIRST_SESSION.id()); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java index 0a433efb7..806a00fa1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java @@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniClientPlugin; import mineplex.core.stats.StatsManager; +import mineplex.core.task.TaskManager; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansPlayerStats; import mineplex.game.clans.clans.playtime.command.PlayTimeCommand; @@ -75,7 +76,7 @@ public class Playtime extends MiniClientPlugin @Override protected PlayingClient AddPlayer(String player) { - return new PlayingClient(_statsManager.Get(player).getStat(ClansPlayerStats.PLAY_TIME.id()) == 0); + return new PlayingClient(Bukkit.getPlayer(player), TaskManager.Instance); } // Seconds diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java index 9dc1c22fe..d170200be 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java @@ -21,7 +21,7 @@ public class cemde extends CommandBase @Override public void Execute(final Player caller, final String[] args) { - Plugin.Get(caller).setStat(ClansPlayerStats.PLAY_TIME.id(), 0); + Plugin.Get(caller).setStat(ClansPlayerStats.PLAY_TIME.id(), args.length == 0 ? 0 : Integer.parseInt(args[0])); _timer.Get(caller).Skipped = false; _timer.Get(caller).InformedTimes.clear(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java index c2eccc0d4..6e9150c54 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java @@ -1,16 +1,23 @@ package mineplex.game.clans.clans.pvptimer; +import java.util.Iterator; + import org.bukkit.Bukkit; import org.bukkit.Sound; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; import mineplex.core.MiniClientPlugin; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; @@ -18,17 +25,26 @@ import mineplex.core.stats.StatsManager; import mineplex.core.task.TaskManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClanTips.TipType; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.event.ClanTipEvent; +import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent; import mineplex.game.clans.clans.playtime.Playtime; import mineplex.game.clans.clans.playtime.command.cemde; import mineplex.game.clans.clans.pvptimer.command.PvPTimerCommand; +import mineplex.game.clans.core.repository.ClanTerritory; +import mineplex.game.clans.spawn.Spawn; +import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; +import mineplex.minecraft.game.classcombat.event.FireballHitEntityEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class PvpTimer extends MiniClientPlugin { - private Playtime _tracker; - public static final String SKIPPED_TASK = "PvpTimer.Skipped"; + private final int[] DISPLAY_TIMES = { 5, 10, 30, 1 * 60, 2 * 60, 5 * 60, 10 * 60, 20 * 60 }; + + private ClansManager _clansManager; + private Playtime _tracker; private static long TIMER_LENGTH = 30 * 60; @@ -36,6 +52,7 @@ public class PvpTimer extends MiniClientPlugin { super("PvP Timer", clans.getPlugin()); _tracker = playtime; + _clansManager = clans; addCommand(new cemde(statsManager, this)); } @@ -58,6 +75,59 @@ public class PvpTimer extends MiniClientPlugin }, caller, "PvpTimer.Skipped"); } + @EventHandler + public void outYouGo(UpdateEvent event) + { + if (event.getType() == UpdateType.SEC) + { + for (Player player : Bukkit.getOnlinePlayers()) + { + if (!hasTimer(player)) continue; + + ClanTerritory territory = _clansManager.getClanUtility().getClaim(player.getLocation()); + + if (territory != null && territory.Owner.equals("Borderlands")) + { + UtilAction.velocity(player, UtilAlg.getTrajectory2d(player.getLocation(), Spawn.ORIGIN), 2.6, true, 0.5, 1, 1.35, true); + player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f); + + UtilPlayer.message(player, " "); + + UtilPlayer.message(player, C.cDRedB + ">>" + C.cRed + " You are not permitted to enter the Borderlands while under PvP Safety."); + + new JsonMessage(C.cGoldB + "> " + C.cGold + "To permanently disable PvP Safety, click ") + .extra("here") + .color("yellow") + .click(ClickEvent.RUN_COMMAND, "/pvptimer yesiconfirmthatiwouldliketodisablemypvptimerforever") + .extra(".") + .color("gray") + .sendToPlayer(player); + + UtilPlayer.message(player, " "); + } + } + } + } + + @EventHandler + public void territoryEnter(PlayerEnterTerritoryEvent event) + { + String from = event.getLastTerritory(); + String to = event.getNewTerritory(); + + if (from == null && "Borderlands".equals(to) + || to == null && "Borderlands".equals(from)) + { + event.setSendMessage(false); + } + } + + @EventHandler + public void clanTip(ClanTipEvent event) + { + event.setCancelled(hasTimer(event.getPlayer()) && event.getTip() == TipType.ENTER_BORDERLANDS); + } + @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { @@ -68,13 +138,13 @@ public class PvpTimer extends MiniClientPlugin Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() { public void run() { - UtilTextMiddle.display(C.cGold + "PvP Timer", "will end in " + UtilTime.MakeStr(getPvPTimerLeft(player) * 1000), 40, 70, 40, player); + UtilTextMiddle.display(C.cGreen + "PvP Safety", C.cGray + "will end in " + UtilTime.MakeStr(getPvPTimerLeft(player) * 1000), 40, 70, 40, player); } }, 10); - UtilPlayer.message(player, F.main("Clans", "You are currently on your PvP timer. It will end in " + F.elem(UtilTime.MakeStr(getPvPTimerLeft(player) * 1000)))); + UtilPlayer.message(player, F.main("Clans", "You are currently safe from PvP because you are a new player. This safety will end in " + F.elem(UtilTime.MakeStr(getPvPTimerLeft(player) * 1000)))); UtilPlayer.message(player, F.main("Clans", "Until it ends, you are immune to, and unable to deal PvP damage.")); - UtilPlayer.message(player, F.main("Clans", "If you would like to disable the PvP timer permanently, then type " + F.elem("/pvptimer") + ", and follow the instructions given.")); + UtilPlayer.message(player, F.main("Clans", "If you would like to disable the PvP safety permanently, then type " + F.elem("/pvp") + ".")); } } @@ -90,67 +160,60 @@ public class PvpTimer extends MiniClientPlugin long time = getPvPTimerLeft(player); PvpTimerClient client = Get(player); - // end if (time <= 2) { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " has ended!")); + UtilPlayer.message(player, F.main("Clans", "PvP Safety has ended!")); UtilPlayer.message(player, F.main("Clans", "You are now completely open to attacks, and you can also attack others.")); player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 0.75f); + continue; } - // 5 secs - else if (time <= 5 && !client.InformedTimes.contains(5)) + + for (int unit : DISPLAY_TIMES) { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " will end in " + F.time("5.0 Seconds"))); - UtilTextMiddle.display("Pvp Timer", "ending in 5 Seconds"); - client.InformedTimes.add(5); - } - // 10 secs - else if (time <= 10 && !client.InformedTimes.contains(10)) - { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " will end in " + F.time("10.0 Seconds"))); - UtilTextMiddle.display("Pvp Timer", "ending in 10 Seconds"); - client.InformedTimes.add(10); - } - // 30 secs - else if (time <= 30 && !client.InformedTimes.contains(30)) - { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " will end in " + F.time("30.0 Seconds"))); - UtilTextMiddle.display("Pvp Timer", "ending in 30 Seconds"); - client.InformedTimes.add(30); - } - // 1 minute - else if (time <= 1 * 60 && !client.InformedTimes.contains(1 * 60)) - { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " will end in " + F.time("1.0 Minute"))); - UtilTextMiddle.display("Pvp Timer", "ending in 1 Minute"); - client.InformedTimes.add(5); - } - // 5 minutes - else if (time <= 5 * 60 && !client.InformedTimes.contains(5 * 60)) - { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " will end in " + F.time("5.0 Minutes"))); - UtilTextMiddle.display("Pvp Timer", "ending in 5 Minutes"); - client.InformedTimes.add(5 * 60); - } - // 10 minutes - else if (time <= 10 * 60 && !client.InformedTimes.contains(10 * 60)) - { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " will end in " + F.time("10.0 Minutes"))); - UtilTextMiddle.display("Pvp Timer", "ending in 10 Minutes"); - client.InformedTimes.add(10 * 60); - } - // 20 minutes - else if (time <= 20 * 60 && !client.InformedTimes.contains(20 * 60)) - { - UtilPlayer.message(player, F.main("Clans", "Your " + F.elem("Pvp Timer") + " will end in " + F.time("20.0 Minutes"))); - UtilTextMiddle.display("Pvp Timer", "ending in 20 Minutes"); - client.InformedTimes.add(20 * 60); + if (time <= unit && !client.InformedTimes.contains(unit)) + { + UtilPlayer.message(player, F.main("Clans", "PvP Safety will end in " + F.time(UtilTime.MakeStr(unit * 1000)))); + UtilTextMiddle.display(C.cGreen + "Pvp Safety", C.cGray + "ending in " + UtilTime.MakeStr(unit * 1000), 20, 80, 20, player); + client.InformedTimes.add(unit); + } } } } } } + @EventHandler + public void onSkill(SkillTriggerEvent event) + { + if (event.GetTargets() == null) + { + return; + } + + if (event.GetTargets().size() == 1 + && event.GetTargets().get(0) instanceof Player + && hasTimer((Player) event.GetTargets().get(0))) + { + event.SetCancelled(true); + } + + for (Iterator iterator = event.GetTargets().iterator(); iterator.hasNext();) + { + Entity entity = iterator.next(); + + if (entity instanceof Player && hasTimer((Player) entity)) + { + iterator.remove(); + } + } + } + + @EventHandler + public void onFireballHit(FireballHitEntityEvent event) + { + event.setCancelled(event.getHitEntity() instanceof Player && hasTimer((Player) event.getHitEntity())); + } + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerAttack(CustomDamageEvent event) { @@ -170,12 +233,12 @@ public class PvpTimer extends MiniClientPlugin { if (damagerTimer) { - UtilPlayer.message(damager, F.main("Clans", "You and " + F.name(victim.getName()) + " are still on your PvP timer. Type " + F.elem("/pvptimer") + " to disable.")); + UtilPlayer.message(damager, F.main("Clans", "You and " + F.name(victim.getName()) + " are still protected from PvP. Type " + F.elem("/pvp") + " to disable.")); bothMsg = true; } else if (damager != null) { - UtilPlayer.message(damager, F.main("Clans", F.name(victim.getName()) + " is still on their Pvp timer.")); + UtilPlayer.message(damager, F.main("Clans", F.name(victim.getName()) + " is still protected from PvP.")); } event.SetCancelled("Pvp Timer"); @@ -185,11 +248,11 @@ public class PvpTimer extends MiniClientPlugin { if (victimTimer) { - if (!bothMsg) UtilPlayer.message(damager, F.main("Clans", "You and " + F.name(victim.getName()) + " are still on your PvP timer. Type " + F.elem("/pvptimer") + " to disable.")); + if (!bothMsg) UtilPlayer.message(damager, F.main("Clans", "You and " + F.name(victim.getName()) + " are still under PvP Safety. Type " + F.elem("/pvp") + " to disable.")); } else if (damager != null) { - UtilPlayer.message(damager, F.main("Clans", "You are still on your PvP timer.")); + UtilPlayer.message(damager, F.main("Clans", "You are still under PvP Safety.")); } event.SetCancelled("PvP Timer"); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/command/PvPTimerCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/command/PvPTimerCommand.java index b8c04949e..104c4155d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/command/PvPTimerCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/command/PvPTimerCommand.java @@ -6,6 +6,7 @@ import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; @@ -25,7 +26,7 @@ public class PvPTimerCommand extends CommandBase { if (Plugin.Get(caller).Skipped) { - UtilPlayer.message(caller, F.main("Clans", "You have skipped your PvP timer.")); + UtilPlayer.message(caller, F.main("Clans", "You have permanently disabled PvP Safety.")); return; } @@ -33,12 +34,12 @@ public class PvPTimerCommand extends CommandBase if (pvpTimerLeft == 0) { - UtilPlayer.message(caller, F.main("Clans", "Your PvP timer has ended.")); + UtilPlayer.message(caller, F.main("Clans", "PvP Safety has already ended.")); } else { - UtilPlayer.message(caller, F.main("Clans", "You have " + F.elem(UtilTime.MakeStr(pvpTimerLeft * 1000)) + " before your PvP timer runs out.")); - new JsonMessage(F.main("Clans", "If you would like to permanently disable Pvp timer, click ")) + UtilPlayer.message(caller, F.main("Clans", "You have " + F.elem(UtilTime.MakeStr(pvpTimerLeft * 1000)) + " before PvP Safety runs out for you.")); + new JsonMessage(F.main("Clans", "If you would like to permanently disable " + C.mBody + "PvP Safety, click ")) .extra("here") .color("green") .click(ClickEvent.RUN_COMMAND, "/pvptimer yesiconfirmthatiwouldliketodisablemypvptimerforever") @@ -53,7 +54,8 @@ public class PvPTimerCommand extends CommandBase if (args[0].equalsIgnoreCase("yesiconfirmthatiwouldliketodisablemypvptimerforever")) { Plugin.disableFor(caller); - UtilPlayer.message(caller, F.main("Clans", "You have disabled your Pvp timer.")); + UtilPlayer.message(caller, F.main("Clans", "You have disabled PvP Safety.")); + UtilPlayer.message(caller, F.main("Clans", "You are now completely open to attacks, and you can also attack others.")); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java index 21cf7f5cb..3de03eadd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java @@ -211,7 +211,7 @@ public class ClansRegions extends MiniPlugin if (_manager.getClaimMap().containsKey(chunkStr)) { - System.out.println("get claim map contains " + chunkStr); + System.out.println("get claim map contains " + chunkStr); // this is really really slowing server startup down. just saying. continue; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/CustomRecipes.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/CustomRecipes.java index 5b6195a54..abeabf652 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/CustomRecipes.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/CustomRecipes.java @@ -1,20 +1,18 @@ package mineplex.game.clans.gameplay; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; - import org.bukkit.Material; import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.inventory.Recipe; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; + public class CustomRecipes implements Listener { - - private static final Material[] DISABLED_RECIPES = { Material.EXPLOSIVE_MINECART, Material.JUKEBOX, Material.FISHING_ROD }; + private static final Material[] DISABLED_RECIPES = { Material.EXPLOSIVE_MINECART, Material.JUKEBOX, Material.FISHING_ROD, Material.BED }; @EventHandler public void onPlayerCraftItem(CraftItemEvent event) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index e5c4b62b9..d969d12b5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -10,7 +10,6 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -39,6 +38,7 @@ import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent.State; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; @@ -65,6 +65,7 @@ import mineplex.core.common.weight.WeightSet; import mineplex.minecraft.game.classcombat.Class.ClientClass; import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; import mineplex.minecraft.game.classcombat.Skill.event.BlockTossEvent; +import mineplex.minecraft.game.classcombat.Skill.event.BlockTossLandEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.DamageManager; @@ -101,6 +102,20 @@ public class Gameplay extends MiniPlugin // } // } + @EventHandler + public void stopBlockTossExploit(BlockTossLandEvent event) + { + int id = event.Entity.getBlockId(); + if (_clansManager.getClanUtility().isClaimed(event.getLocation()) + && (Material.getMaterial(id).name().endsWith("_PLATE") + || id == Material.STONE_BUTTON.getId() + || id == Material.WOOD_BUTTON.getId() + || id == Material.LEVER.getId())) + { + event.setCancelled(true); + } + } + @EventHandler public void onPlayerFishing(PlayerFishEvent event) { @@ -434,7 +449,7 @@ public class Gameplay extends MiniPlugin { final Block block = event.getBlock(); - if (_clansManager.getClanUtility().isSafe(block.getLocation())) + if (_clansManager.getClanUtility().getClaim(block.getLocation()) != null) { return; } @@ -471,15 +486,9 @@ public class Gameplay extends MiniPlugin } @EventHandler - public void killRain(UpdateEvent event) + public void killRain(WeatherChangeEvent event) { - if (event.getType() != UpdateType.TWOSEC){ - for (World world : Bukkit.getWorlds()){ - world.setWeatherDuration(0); - world.setThunderDuration(0); - world.setThundering(false); - } - } + event.setCancelled(event.toWeatherState()); } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java index 9539a639e..167d189b1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java @@ -10,7 +10,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; -import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilFile; import mineplex.core.common.util.UtilFile.ChunkType; @@ -19,8 +18,8 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; -import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClanTips.TipType; +import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.gameplay.safelog.npc.NPCManager; public class SafeLog extends MiniPlugin @@ -96,8 +95,7 @@ public class SafeLog extends MiniPlugin @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - event.setQuitMessage(null); - UtilServer.broadcast(F.sys("Quit", event.getPlayer().getName())); + event.setQuitMessage(F.sys("Quit", event.getPlayer().getName())); onPlayerQuit(event.getPlayer()); } @@ -105,8 +103,7 @@ public class SafeLog extends MiniPlugin @EventHandler public void onPlayerKicked(PlayerKickEvent event) { - event.setLeaveMessage(null); - UtilServer.broadcast(F.sys("Quit", event.getPlayer().getName())); + event.setLeaveMessage(F.sys("Quit", event.getPlayer().getName())); onPlayerQuit(event.getPlayer()); } @@ -115,7 +112,6 @@ public class SafeLog extends MiniPlugin public void onPlayerJoin(PlayerJoinEvent event) { event.setJoinMessage(null); - UtilServer.broadcast(F.sys("Join", event.getPlayer().getName())); onPlayerJoin(event.getPlayer()); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java index 9d4e04f83..c37e78a56 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java @@ -13,6 +13,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; +import org.bukkit.metadata.FixedMetadataValue; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -20,7 +21,6 @@ import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilFile; import mineplex.core.common.util.UtilFile.ChunkType; import mineplex.core.common.util.UtilFile.DataFileChunk; -import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; @@ -28,6 +28,8 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; +import mineplex.game.clans.Clans; +import mineplex.game.clans.clans.ClansManager; public class CombatLogNPC { @@ -188,6 +190,7 @@ public class CombatLogNPC { Location spawnLoc = player.getLocation(); Skeleton skel = player.getWorld().spawn(spawnLoc, Skeleton.class); + skel.setMetadata("CombatLogNPC", new FixedMetadataValue(ClansManager.getInstance().getPlugin(), player.getUniqueId().toString())); skel.teleport(spawnLoc); skel.setHealth(_spawnHealth); UtilEnt.Vegetate(skel); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java index 57b3ae3c2..5998a312f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java @@ -8,10 +8,12 @@ import org.bukkit.GameMode; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.world.ChunkUnloadEvent; import mineplex.core.MiniPlugin; @@ -20,6 +22,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.spawn.Spawn; import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class NPCManager extends MiniPlugin @@ -74,6 +77,18 @@ public class NPCManager extends MiniPlugin } } + @EventHandler + public void killNpcs(PlayerJoinEvent event) + { + for (LivingEntity entity : Spawn.getSpawnWorld().getLivingEntities()) + { + if (entity.hasMetadata("CombatLogNPC")) + { + entity.remove(); + } + } + } + public void despawnLogoutNpc(Player player) { CombatLogNPC npc = getLogoutNpc(player); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java index 83a5c7dcc..ab9a84425 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java @@ -55,6 +55,8 @@ public class CustomItem private boolean _dullEnchantment; + public String OriginalOwner = null; + public String getUuid() { return _uuid; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index 1c30244f5..b6505c23b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -8,7 +8,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -23,6 +25,7 @@ import com.google.gson.GsonBuilder; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -64,7 +67,6 @@ import mineplex.game.clans.items.legendaries.WindBlade; import mineplex.game.clans.items.smelting.SmeltingListener; import mineplex.game.clans.items.ui.GearShop; import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory; - import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot; @@ -361,6 +363,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable } catch (Exception exception) { + exception.printStackTrace(); System.out.println("=========="); System.out.println("GearManager parse problem :"); System.out.println(serialization); @@ -481,7 +484,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable if (packet instanceof PacketPlayOutSetSlot) { PacketPlayOutSetSlot slotPacket = (PacketPlayOutSetSlot) packet; - slotPacket.c = maskItem(slotPacket.c); // Mask all out-going item + slotPacket.c = maskItem(slotPacket.c, packetInfo.getPlayer()); // Mask all out-going item // packets } else if (packet instanceof PacketPlayOutWindowItems) @@ -490,7 +493,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable for (int i = 0; i < itemsPacket.b.length; i++) { - itemsPacket.b[i] = maskItem(itemsPacket.b[i]); // Mask all + itemsPacket.b[i] = maskItem(itemsPacket.b[i], packetInfo.getPlayer()); // Mask all // out-going // item packets ItemStack item = CraftItemStack.asCraftMirror(itemsPacket.b[i]); @@ -514,7 +517,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable return item; } - private net.minecraft.server.v1_8_R3.ItemStack maskItem(net.minecraft.server.v1_8_R3.ItemStack item) + private net.minecraft.server.v1_8_R3.ItemStack maskItem(net.minecraft.server.v1_8_R3.ItemStack item, Player player) { // Cannot mask a null item if (item == null) @@ -533,18 +536,21 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable List lore = new ArrayList(); + CustomItem ci = parseItem(originalItem); + for (String line : originalMeta.getLore()) { - if (!line.startsWith(ITEM_SERIALIZATION_TAG)) // Remove - // serialization - // lines from - // out-going lore + if (!line.startsWith(ITEM_SERIALIZATION_TAG)) { lore.add(line); - }else{ } } + if (ci != null && _legendaryWeights.elements().contains(ci.getClass())) + { + lore.add(C.cWhite + "Original Owner: " + C.cYellow + (ci.OriginalOwner == null ? "You" : Bukkit.getOfflinePlayer(UUID.fromString(ci.OriginalOwner)).getName())); + } + net.minecraft.server.v1_8_R3.ItemStack newItem = CraftItemStack.asNMSCopy(originalItem); CraftItemStack newCopy = CraftItemStack.asCraftMirror(newItem); ItemMeta newMeta = newCopy.getItemMeta(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java index fbc03131d..1f9ecfdc2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java @@ -3,17 +3,20 @@ package mineplex.game.clans.items; import java.util.HashSet; import java.util.Set; -import mineplex.game.clans.items.legendaries.LegendaryItem; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; - import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.game.clans.items.legendaries.LegendaryItem; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; + /** * PlayerGear caches and manages a players set of {@link CustomItem}s that they * currently wield. @@ -55,7 +58,17 @@ public class PlayerGear if (item != null && item instanceof LegendaryItem) { LegendaryItem legendary = (LegendaryItem) item; + legendary.preUpdate(getPlayer()); legendary.update(getPlayer()); + + if (legendary.OriginalOwner == null) + { + legendary.OriginalOwner = getPlayer().getUniqueId().toString(); + UtilServer.broadcast(F.main("Clans", F.elem(getPlayer().getName()) + " has picked up " + F.vowelAN(legendary.getDisplayName()) + " " + legendary.getDisplayName() + C.mBody + ".")); + UtilTextMiddle.display(C.cDPurple + "Legendary", F.elem(getPlayer().getName()) + C.cWhite + " picked up " + F.vowelAN(legendary.getDisplayName()) + " " + legendary.getDisplayName() + C.cWhite + "."); + + getPlayer().setItemInHand(legendary.toItemStack()); + } } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java index d28524af0..256bae574 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java @@ -62,7 +62,7 @@ public class GiantsBroadsword extends LegendaryItem private void buffPlayer(Player player) { - grantPotionEffect(player, PotionEffectType.SLOW, 20, 10); - grantPotionEffect(player, PotionEffectType.REGENERATION, 1, 10); + grantPotionEffect(player, PotionEffectType.SLOW, 40, 10); + grantPotionEffect(player, PotionEffectType.REGENERATION, 40, 10); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java index ffa649364..13094784a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java @@ -30,6 +30,10 @@ public class LegendaryItem extends CustomItem // Leave implementation to potential subtypes } + public void preUpdate(Player wielder) + { + } + public void onAttack(CustomDamageEvent event, Player wielder) { // Leave implementation to potential subtypes diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java index 921f00d61..1ef288b15 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java @@ -74,7 +74,7 @@ public class WindBlade extends LegendaryItem _burnoutThreshold = 0; } - if (_messageTimer % 20 == 0) + if (_messageTimer % 5 == 0) { UtilPlayer.message(wielder, F.main("Wind Blade", "Flight power damaged whilst scraping the ground! Repairs will be finish in " + F.time(UtilTime.MakeStr(burnoutRemaining)) + ".")); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java index 78169ea47..459a18701 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java @@ -89,7 +89,6 @@ public abstract class ClansShopPage> extends Sh addShopItem(index, item, (byte) 0, displayName, 1); } - public void addShopItem(int index, ClansShopItem item) { addShopItem(index, item, (byte) 0); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java index 53ef5e8a1..a04d444d0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java @@ -54,6 +54,7 @@ public class Spawn extends MiniPlugin public static final int SHOP_RADIUS = 48; public static final String COMBAT_TAG_NAME = "Unsafe"; public static final long COMBAT_TAG_DURATION = 15000; + public static final Location ORIGIN = new Location(getSpawnWorld(), 0, 0, 0); private static Spawn _instance; public static Spawn getInstance() { return _instance; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java index cc785d827..ac0f637e4 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import org.bukkit.Color; import org.bukkit.FireworkEffect.Type; @@ -31,24 +30,21 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilItem; -import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.donation.DonationManager; -import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketHandler; -import mineplex.core.packethandler.PacketInfo; import mineplex.core.scoreboard.ScoreboardManager; import mineplex.core.scoreboard.elements.ScoreboardElement; import mineplex.core.task.TaskManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.ClansPlayerTasks; import mineplex.game.clans.clans.event.ClanJoinEvent; import mineplex.game.clans.clans.event.ClanTipEvent; import mineplex.game.clans.clans.playtime.Playtime; import mineplex.game.clans.economy.GoldManager; -import net.minecraft.server.v1_8_R3.PacketPlayOutChat; /** * @@ -286,6 +282,13 @@ public abstract class Tutorial implements ScoreboardElement, Listener _inTutorial.remove(player.getName()); onFinished(player); + if (_playtime.Get(player).FirstSession) + { + _playtime.Get(player).StartTime = System.currentTimeMillis(); + _playtime.Get(player).FirstSession = false; + TaskManager.Instance.completedTask(null, player, ClansPlayerTasks.FIRST_SESSION.id()); + } + _manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(_manager.getPlugin(), new Runnable() { public void run() @@ -441,6 +444,13 @@ public abstract class Tutorial implements ScoreboardElement, Listener player.showPlayer(other); } } + + if (_playtime.Get(player).FirstSession) + { + _playtime.Get(player).StartTime = System.currentTimeMillis(); + _playtime.Get(player).FirstSession = false; + TaskManager.Instance.completedTask(null, player, ClansPlayerTasks.FIRST_SESSION.id()); + } } public boolean isInTutorial(final Player player) @@ -503,12 +513,6 @@ public abstract class Tutorial implements ScoreboardElement, Listener { public void run(Boolean data) { - if (_playtime.Get(player).FirstSession) - { - _playtime.Get(player).StartTime = System.currentTimeMillis(); - _playtime.Get(player).FirstSession = false; - } - cancelFor(player); } }, player, String.format(SKIPPED_TASK, _technicalName)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/gettingstarted/TutorialGettingStarted.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/gettingstarted/TutorialGettingStarted.java index c91e87436..6e924c468 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/gettingstarted/TutorialGettingStarted.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/gettingstarted/TutorialGettingStarted.java @@ -53,12 +53,6 @@ public class TutorialGettingStarted extends Tutorial { player.resetPlayerTime(); player.teleport(Spawn.getEastSpawn()); - - if (_playtime.Get(player).FirstSession) - { - _playtime.Get(player).StartTime = System.currentTimeMillis(); - _playtime.Get(player).FirstSession = false; - } } @Override diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 41b2081a3..de561f590 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -13,6 +13,7 @@ import mineplex.core.aprilfools.AprilFoolsManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.creature.Creature; import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; @@ -66,7 +67,6 @@ import mineplex.minecraft.game.classcombat.shop.ClassCombatShop; import mineplex.minecraft.game.classcombat.shop.ClassShopManager; import mineplex.minecraft.game.core.IRelation; import mineplex.minecraft.game.core.combat.CombatManager; -import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.fire.Fire; @@ -189,7 +189,7 @@ public class Hub extends JavaPlugin implements IRelation @Override public void onDisable() { - + getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } @Override diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClientClass.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClientClass.java index 74e19ca6d..bddac25dd 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClientClass.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClientClass.java @@ -369,7 +369,7 @@ public class ClientClass UtilPlayer.message(caller, F.main("Skill", "Listing Class Skills:")); for (SkillType type : SkillType.values()) - if (caller.isOp() || type != SkillType.Class) + if ((caller != null && caller.isOp()) || type != SkillType.Class) if (_skillMap.containsKey(type)) UtilPlayer.message(caller, F.desc(type.toString(), _skillMap.get(type).GetName() + " Lvl" + _skillMap.get(type).getLevel(caller))); } diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Brute/BlockToss.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Brute/BlockToss.java index e7fcc5bd5..cb7be682b 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Brute/BlockToss.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Brute/BlockToss.java @@ -37,6 +37,7 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.minecraft.game.classcombat.Skill.SkillCharge; import mineplex.minecraft.game.classcombat.Skill.SkillFactory; +import mineplex.minecraft.game.classcombat.Skill.event.BlockTossEvent; import mineplex.minecraft.game.classcombat.Skill.event.BlockTossExpireEvent; import mineplex.minecraft.game.classcombat.Skill.event.BlockTossLandEvent; import mineplex.minecraft.game.classcombat.Skill.event.SkillEvent; @@ -239,13 +240,15 @@ public class BlockToss extends SkillCharge implements IThrown //Throw cur.eject(); double mult = Math.max(0.4, charge * 2); - + + Material mat = Material.getMaterial(block.getBlockId()); + //Action UtilAction.velocity(block, cur.getLocation().getDirection(), mult, false, 0, 0, 1, true); Factory.Projectile().AddThrow(block, cur, this, -1, true, true, true, true, null, 0, 0, null, 0, UpdateType.FASTEST, 1.2f); - //Event + // Generic Event UtilServer.getServer().getPluginManager().callEvent(new SkillEvent(cur, GetName(), ClassType.Brute)); } } @@ -369,7 +372,7 @@ public class BlockToss extends SkillCharge implements IThrown { if (!event.getBlock().getType().isSolid()) // Falling block is landing and turning block from air to type { - BlockTossLandEvent landEvent = new BlockTossLandEvent(event.getBlock()); + BlockTossLandEvent landEvent = new BlockTossLandEvent(event.getBlock(), ((FallingBlock) event.getEntity())); Bukkit.getServer().getPluginManager().callEvent(landEvent); if (landEvent.isCancelled()) diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/FireBlast.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/FireBlast.java index 46ec2eaba..f205452ae 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/FireBlast.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/FireBlast.java @@ -21,8 +21,10 @@ import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.minecraft.game.classcombat.Skill.SkillActive; import mineplex.minecraft.game.classcombat.Skill.SkillFactory; +import mineplex.minecraft.game.classcombat.event.FireballHitEntityEvent; public class FireBlast extends SkillActive { @@ -93,7 +95,7 @@ public class FireBlast extends SkillActive if (!(proj.getShooter() instanceof Player)) return; - + Player player = (Player)proj.getShooter(); //Level @@ -105,7 +107,16 @@ public class FireBlast extends SkillActive for (LivingEntity cur : hitMap.keySet()) { double range = hitMap.get(cur); - + + FireballHitEntityEvent evt = new FireballHitEntityEvent(proj, cur); + + UtilServer.getServer().getPluginManager().callEvent(evt); + + if (evt.isCancelled()) + { + continue; + } + //Damage Event Factory.Condition().Factory().Ignite(GetName(), cur, player, (2 + (1 * level)) * range, false, false); diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/event/BlockTossLandEvent.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/event/BlockTossLandEvent.java index 4cc50dd18..908e13720 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/event/BlockTossLandEvent.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/event/BlockTossLandEvent.java @@ -9,9 +9,11 @@ import org.bukkit.event.HandlerList; public class BlockTossLandEvent extends BlockTossEvent { - - public BlockTossLandEvent(Block block) + public FallingBlock Entity; + + public BlockTossLandEvent(Block block, FallingBlock fallingBlock) { super(block); + Entity = fallingBlock; } } diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/event/FireballHitEntityEvent.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/event/FireballHitEntityEvent.java new file mode 100644 index 000000000..43c9b1555 --- /dev/null +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/event/FireballHitEntityEvent.java @@ -0,0 +1,52 @@ +package mineplex.minecraft.game.classcombat.event; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Projectile; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class FireballHitEntityEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Projectile _projectile; + private LivingEntity _hitEntity; + + private boolean _cancelled; + + public FireballHitEntityEvent(Projectile proj, LivingEntity entity) + { + _projectile = proj; + _hitEntity = entity; + } + + public Projectile getProjectile() + { + return _projectile; + } + + public LivingEntity getHitEntity() + { + return _hitEntity; + } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + public boolean isCancelled() + { + return _cancelled; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index e2ca772b3..cc656c818 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -6,15 +6,9 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import mineplex.core.CustomTagFix; import mineplex.core.FoodDupeFix; import mineplex.core.PacketsInteractionFix; -import mineplex.core.account.CoreClient; -import mineplex.core.customdata.CustomDataManager; -import mineplex.core.giveaway.GiveawayManager; -import mineplex.core.globalpacket.GlobalPacketManager; -import net.minecraft.server.v1_8_R3.BiomeBase; -import net.minecraft.server.v1_8_R3.MinecraftServer; -import mineplex.core.CustomTagFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; @@ -22,15 +16,19 @@ import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blood.Blood; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.common.util.FileUtil; import mineplex.core.common.util.UtilServer; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.creature.Creature; +import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.friend.FriendManager; import mineplex.core.gadget.GadgetManager; import mineplex.core.give.Give; +import mineplex.core.giveaway.GiveawayManager; +import mineplex.core.globalpacket.GlobalPacketManager; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; import mineplex.core.inventory.InventoryManager; @@ -61,6 +59,8 @@ import mineplex.core.visibility.VisibilityManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; import nautilus.game.arcade.game.GameServerConfig; +import net.minecraft.server.v1_8_R3.BiomeBase; +import net.minecraft.server.v1_8_R3.MinecraftServer; public class Arcade extends JavaPlugin { @@ -186,6 +186,8 @@ public class Arcade extends JavaPlugin if (_gameManager.GetGame() != null) if (_gameManager.GetGame().WorldData != null) _gameManager.GetGame().WorldData.Uninitialize(); + + getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } public GameServerConfig ReadServerConfig() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java index 23b3ec1b1..03ad8960c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java @@ -465,7 +465,7 @@ public class Christmas extends SoloGame { SantaSay("Well done! You've saved Christmas!", ChristmasAudio.END_WIN2); - for (Player player : GetPlayers(false)) + for (final Player player : GetPlayers(false)) { if (Manager.IsRewardItems()) { diff --git a/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/modules/clans/ClansOutpost.java b/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/modules/clans/ClansOutpost.java index a120c8bfa..79061f49c 100644 --- a/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/modules/clans/ClansOutpost.java +++ b/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/modules/clans/ClansOutpost.java @@ -34,7 +34,6 @@ public class ClansOutpost public void Build() { - _build = new ArrayList(); for (int y=-1 ; y <= 6 ; y++)