From 2504493ebc9cc9b0043d7a64f949f2237ba71381 Mon Sep 17 00:00:00 2001 From: Thanos paravantis Date: Sun, 4 Oct 2015 00:34:00 +0300 Subject: [PATCH 1/3] Fixed four super paintball bugs. - Projectiles could paint wool in the waiting lobby. - When players fell in the void, they didn't got killed. - Players that were painted could take off their armor. - Players that were painted could logout and the skeleton would still stay there. --- .../game/games/paintball/Paintball.java | 140 +++++++++++------- 1 file changed, 88 insertions(+), 52 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java index 550bdb153..54d387758 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java @@ -4,17 +4,44 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.condition.Condition.ConditionType; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.events.PlayerPrepareTeleportEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.GameTeam.PlayerState; +import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.games.paintball.kits.KitMachineGun; +import nautilus.game.arcade.game.games.paintball.kits.KitRifle; +import nautilus.game.arcade.game.games.paintball.kits.KitShotgun; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.stats.KillFastStatTracker; +import nautilus.game.arcade.stats.LastStandStatTracker; +import nautilus.game.arcade.stats.MedicStatTracker; +import nautilus.game.arcade.stats.WinFastStatTracker; +import nautilus.game.arcade.stats.WinWithoutLosingTeammateStatTracker; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Effect; -import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.EnderPearl; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Snowball; @@ -22,9 +49,11 @@ import org.bukkit.entity.ThrownPotion; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent; @@ -34,31 +63,6 @@ import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.minecraft.game.core.condition.Condition.ConditionType; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.GameType; -import nautilus.game.arcade.events.GameStateChangeEvent; -import nautilus.game.arcade.events.PlayerPrepareTeleportEvent; -import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.TeamGame; -import nautilus.game.arcade.game.GameTeam.PlayerState; -import nautilus.game.arcade.game.games.paintball.kits.*; -import nautilus.game.arcade.kit.Kit; -import nautilus.game.arcade.stats.KillFastStatTracker; -import nautilus.game.arcade.stats.LastStandStatTracker; -import nautilus.game.arcade.stats.MedicStatTracker; -import nautilus.game.arcade.stats.WinFastStatTracker; -import nautilus.game.arcade.stats.WinWithoutLosingTeammateStatTracker; - public class Paintball extends TeamGame { public static class ReviveEvent extends PlayerEvent @@ -137,7 +141,6 @@ public class Paintball extends TeamGame this.GetTeamList().get(1).SetName("Nether"); } - @EventHandler(priority = EventPriority.HIGHEST) public void ColorArmor(PlayerPrepareTeleportEvent event) { @@ -161,31 +164,44 @@ public class Paintball extends TeamGame @EventHandler public void Paint(ProjectileHitEvent event) { - if (event.getEntity() instanceof ThrownPotion) - return; + // Fixed projectile wool painting in waiting lobby. - byte color = 3; - if (event.getEntity() instanceof EnderPearl) - color = 14; - - Location loc = event.getEntity().getLocation().add(event.getEntity().getVelocity()); - - for (Block block : UtilBlock.getInRadius(loc, 1.5d).keySet()) + if (IsLive() || GetState() == GameState.End) { - if (block.getType() != Material.WOOL && block.getType() != Material.STAINED_CLAY) - continue; + if (event.getEntity() instanceof ThrownPotion) + return; + + byte color = 3; + if (event.getEntity() instanceof EnderPearl) + color = 14; + + Location loc = event.getEntity().getLocation().add(event.getEntity().getVelocity()); + + for (Block block : UtilBlock.getInRadius(loc, 1.5d).keySet()) + { + if (block.getType() != Material.WOOL && block.getType() != Material.STAINED_CLAY) + continue; + + block.setData(color); + } + + if (color == 3) loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 8); + else loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 10); - block.setData(color); } - - if (color == 3) loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 8); - else loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 10); } @EventHandler public void PlayerQuit(PlayerQuitEvent event) { - _doubles.remove(event.getPlayer()); + Player player = event.getPlayer(); + + if (_doubles.containsKey(player)) + { + PlayerCopy copy = _doubles.get(player); + copy.GetEntity().remove(); + _doubles.remove(player); + } } @EventHandler @@ -194,7 +210,9 @@ public class Paintball extends TeamGame if (event.GetDamageePlayer() == null) event.SetCancelled("Not Player"); - if (event.GetProjectile() == null) + // Fixed void damage being blocked from this check. + + if (event.GetProjectile() == null && event.GetCause() != DamageCause.VOID) event.SetCancelled("No Projectile"); } @@ -203,7 +221,7 @@ public class Paintball extends TeamGame { if (!IsLive()) return; - + if (event.GetProjectile() == null) return; @@ -211,23 +229,28 @@ public class Paintball extends TeamGame return; //Negate + event.AddMod("Negate", "Negate", -event.GetDamageInitial(), false); event.AddMod("Paintball", "Paintball", 2, true); event.AddKnockback("Paintball", 2); Player damagee = event.GetDamageePlayer(); - if (damagee == null) return; + if (damagee == null) + return; Player damager = event.GetDamagerPlayer(true); - if (damager == null) return; - + if (damager == null) + return; + GameTeam damageeTeam = GetTeam(damagee); - if (damageeTeam == null) return; + if (damageeTeam == null) + return; GameTeam damagerTeam = GetTeam(damager); - if (damagerTeam == null) return; - + if (damagerTeam == null) + return; + if (damagerTeam.equals(damageeTeam)) return; @@ -257,8 +280,21 @@ public class Paintball extends TeamGame Player player = event.GetDamagerPlayer(true); if (player != null) player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1f, 3f); - } + } + @EventHandler + public void ArmorRemoveCancel(InventoryClickEvent event) + { + HumanEntity player = event.getWhoClicked(); + + // Fixed armor being taken off while spectating after being painted. + + if (!IsAlive(player)) + { + event.setCancelled(true); + } + } + public boolean Color(Player player, int amount) { //Get Non-Coloured From 6c73b1a5acb43db8294d5e6dbc3c168ce382148b Mon Sep 17 00:00:00 2001 From: alexmack929 Date: Sun, 4 Oct 2015 15:24:58 +0100 Subject: [PATCH 2/3] Start moving i18n into master. --- .../mineplex/core/common/lang/IntlString.java | 232 ++++++++++++++++++ .../src/mineplex/core/common/lang/Lang.java | 154 ++++++++++++ 2 files changed, 386 insertions(+) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/IntlString.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/IntlString.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/IntlString.java new file mode 100644 index 000000000..fada15f15 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/IntlString.java @@ -0,0 +1,232 @@ +package mineplex.core.common.lang; + +import java.text.Format; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public class IntlString +{ + + public static IntlString[] toIntl(String... strings) + { + IntlString[] intl = new IntlString[strings.length]; + + for (int i = 0; i < strings.length; i++) { + final String string = strings[i]; + intl[i] = new IntlString("") + { + public String tr(Locale locale) + { + return string; + } + }; + } + + return intl; + } + + /** + * An empty {@link IntlString}. + */ + public static final IntlString EMPTY = toIntl("")[0]; + + private final Argument key; + private final List> arguments = new ArrayList<>(); + + public IntlString(String key, ChatColor... styles) + { + this.key = new Argument<>(key, styles); + } + + IntlString(String key, String style) + { + this.key = new Argument<>(key, style); + } + + private IntlString arg(Argument argument) + { + IntlString result = new IntlString(getKey().getArgument(), getKey().getStyle()); + result.arguments.addAll(getArguments()); + result.arguments.add(argument); + + return result; + } + + public Argument getKey() + { + return key; + } + + public List> getArguments() + { + return Collections.unmodifiableList(arguments); + } + + public IntlString arg(Object value, ChatColor... styles) + { + return arg(new Argument<>(value, styles)); + } + + public IntlString arg(Object value, String style) + { + return arg(new Argument<>(value, style)); + } + + public String tr() + { + return tr(Locale.getDefault()); + } + + public String tr(Entity entity) + { + if (entity instanceof Player) + return tr((Player) entity); + else + return tr(); + } + + public String tr(Player player) + { + return tr(Lang.getPlayerLocale(player)); + } + + public String tr(Locale locale) + { + if (locale == null) + locale = Locale.getDefault(); + + String formatString = Lang.get(getKey().getArgument(), locale); + + if (getKey().getArgument().equals("stats.achievements.disabled.requires.0.players")) + { + int x = 8; + } + + if (getArguments().isEmpty()) + return getKey().getStyle() + formatString; + else + { + MessageFormat format = new MessageFormat(formatString, locale); + + Format[] formats = format.getFormatsByArgumentIndex(); + Object[] argArray = new Object[getArguments().size()]; + for (int i = 0; i < formats.length; i++) + { + argArray[i] = getArguments().get(i); + if (argArray[i] instanceof IntlString) + argArray[i] = ((IntlString) argArray[i]).tr(locale); + + if (formats[i] != null) + { + argArray[i] = formats[i].format(argArray[i]); + format.setFormatByArgumentIndex(i, null); + } + + String style = getArguments().get(i).getStyle(); + if (!style.isEmpty()) + argArray[i] = style + argArray[i] + ChatColor.RESET; + + argArray[i] = argArray[i] + getKey().getStyle(); + } + + return getKey().getStyle() + format.format(argArray, new StringBuffer(), null).toString(); + } + } + + @Override + public boolean equals(Object o) + { + if (!(o instanceof IntlString)) + return false; + + IntlString s = (IntlString) o; + + return getKey().equals(s.getKey()) && getArguments().equals(s.getArguments()); + } + + @Override + public int hashCode() + { + return toString().hashCode(); + } + + @Override + public String toString() + { + return toEnglishString(); + } + + public String toEnglishString() + { + return tr(Locale.ENGLISH); + } + + private static class Argument + { + private final T argument; + private final String style; + + public Argument(T value, ChatColor... styles) + { + this.argument = value; + + String s = ""; + ChatColor color = null; + for (ChatColor style : styles) + { + if (style.isColor()) + color = style; + else if (style.isFormat()) + s += style; + } + + this.style = ChatColor.getLastColors((color == null ? "" : color) + s); + } + + public Argument(T value, String style) + { + this.argument = value; + this.style = style == null ? "" : ChatColor.getLastColors(style); + } + + public T getArgument() + { + return argument; + } + + public String getStyle() + { + return style; + } + + @Override + public boolean equals(Object o) + { + if (!(o instanceof Argument)) + return false; + + Argument p = (Argument) o; + + return getArgument().equals(p.getArgument()) && getStyle().equals(p.getStyle()); + } + + @Override + public int hashCode() + { + return toString().hashCode(); + } + + @Override + public String toString() + { + return getStyle() + getArgument(); + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java new file mode 100644 index 000000000..b91fe232a --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/lang/Lang.java @@ -0,0 +1,154 @@ +package mineplex.core.common.lang; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import mineplex.core.common.util.F; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public final class Lang +{ + public static interface PlayerLocaleFunction + { + public Locale getLocaleOfPlayer(Player player); + } + + + private static PlayerLocaleFunction _playerLocaleFunction = null; + private static final Map _localeResourceBundles = Collections.synchronizedMap(new HashMap()); + + + public Lang() + { + init(); + } + + + private void init() + { + System.out.println(F.main("i18n","Attempting to initialize resource bundles...")); + + try + { + // Locales over which we should iterate and load. + for (Locale loc : new Locale[] { + Locale.ENGLISH, + Locale.GERMAN + }) + { + ResourceBundle bundle = ResourceBundle.getBundle("mineplex.core.common.lang.MineplexBundle", loc); + _localeResourceBundles.put(loc, bundle); + System.out.println("Loaded " + loc.toString() + "..."); + } + } + catch (MissingResourceException e) + { + System.err.println("AN ERROR OCCURED WHILE ATTEMPTING TO LOAD RESOURCE LOCALES"); + // For now at least, crash the runtime. + throw new RuntimeException(e); + } + } + + public static PlayerLocaleFunction getPlayerLocaleFunction() + { + return _playerLocaleFunction; + } + + public static void setPlayerLocaleFunction(PlayerLocaleFunction playerLocaleFunction) + { + _playerLocaleFunction = playerLocaleFunction; + } + + public static Locale getPlayerLocale(Player player) + { + if (getPlayerLocaleFunction() == null) + return Locale.getDefault(); + else + return getPlayerLocaleFunction().getLocaleOfPlayer(player); + } + + public static ResourceBundle getResourceBundle(Locale locale) + { + synchronized (_localeResourceBundles) + { + if (_localeResourceBundles.containsKey(locale)) + return _localeResourceBundles.get(locale); + else + { + return _localeResourceBundles.get(Locale.ENGLISH); + } + } + } + + public static ResourceBundle getBestResourceBundle(Locale locale) + { + ResourceBundle bundle = getResourceBundle(locale); + + if (bundle == null && !locale.equals(Locale.getDefault())) + bundle = getResourceBundle(Locale.getDefault()); + + if (bundle == null && !locale.equals(Locale.ENGLISH)) + bundle = getResourceBundle(Locale.ENGLISH); + + return bundle; + } + + /** + * Shorthand method for obtaining and translating a key. + */ + public static String tr(String key, Entity entity, Object... args) + { + IntlString string = key(key); + + for (Object a : args) + string.arg(a); + + return string.tr(entity); + } + + public static String get(String key) + { + return get(key, (Locale) null); + } + + public static String get(String key, Locale locale) + { + if (key == null) + return null; + else if (key.isEmpty()) + return ""; + else + { + if (locale == null) + locale = Locale.getDefault(); + + ResourceBundle bundle = getBestResourceBundle(locale); + if (bundle == null) + return null; + + return bundle.getString(key); + } + } + + public static String get(String key, Player player) + { + return get(key, getPlayerLocale(player)); + } + + public static IntlString key(String key, ChatColor... styles) + { + return new IntlString(key, styles); + } + + public static IntlString key(String key, String style) + { + return new IntlString(key, style); + } +} \ No newline at end of file From e2e2356b04398e2c34f7961ede4eda812bf718f0 Mon Sep 17 00:00:00 2001 From: Cheese Date: Tue, 6 Oct 2015 13:25:15 +1100 Subject: [PATCH 3/3] stuffs --- .../core/notifier/NotificationManager.java | 8 ++--- .../core/preferences/ui/PreferencesPage.java | 33 +++++++++++++------ .../src/mineplex/hub/modules/JumpManager.java | 11 +++++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java index d5097e318..99e3cc185 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java @@ -60,18 +60,18 @@ public class NotificationManager extends MiniPlugin if (rank == Rank.ALL) { - UtilPlayer.message(player, C.cWhite + "50% Off Sale! " + " Purchase " + C.cAqua + C.Bold + "Ultra Rank" + C.cWhite + " for $15"); + UtilPlayer.message(player, C.cWhite + " 50% Off Sale! " + " Purchase " + C.cAqua + C.Bold + "Ultra Rank" + C.cWhite + " for $15"); } else if (rank == Rank.ULTRA) { - UtilPlayer.message(player, C.cWhite + "50% Off Sale! " + " Upgrade to " + C.cPurple + C.Bold + "Hero Rank" + C.cWhite + " for $15!"); + UtilPlayer.message(player, C.cWhite + " 50% Off Sale! " + " Upgrade to " + C.cPurple + C.Bold + "Hero Rank" + C.cWhite + " for $15!"); } else if (rank == Rank.HERO) { - UtilPlayer.message(player, C.cWhite + "50% Off Sale! " + "Upgrade to " + C.cGreen + C.Bold + "Legend Rank" + C.cWhite + " for $15!"); + UtilPlayer.message(player, C.cWhite + " 50% Off Sale! " + "Upgrade to " + C.cGreen + C.Bold + "Legend Rank" + C.cWhite + " for $15!"); } - UtilPlayer.message(player, C.cWhite + " Visit " + F.link("www.mineplex.com/shop") + " for 50% Off Ranks!"); + UtilPlayer.message(player, C.cWhite + " Visit " + F.link("www.mineplex.com/shop") + C.cWhite + " for 50% Off Ranks!"); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java index 8007a3aef..1fb8c4d0d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java @@ -165,7 +165,19 @@ public class PreferencesPage extends ShopPageBase