From ab3d2ba098ffeee08396d10a97f0233a129bb377 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 28 Nov 2015 00:23:18 +1100 Subject: [PATCH 1/3] updated tutorials. added worldmanager to cull entities. --- .../src/mineplex/game/clans/Clans.java | 2 + .../types/TutorialGettingStarted.java | 64 +++++++-- .../game/clans/world/WorldManager.java | 123 ++++++++++++++++++ 3 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java 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 2ade3e90f..26307cfa1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -44,6 +44,7 @@ import mineplex.game.clans.shop.farming.FarmingShop; import mineplex.game.clans.shop.mining.MiningShop; import mineplex.game.clans.shop.pvp.PvpShop; import mineplex.game.clans.spawn.travel.TravelShop; +import mineplex.game.clans.world.WorldManager; import net.minecraft.server.v1_8_R3.MinecraftServer; public class Clans extends JavaPlugin @@ -128,6 +129,7 @@ public class Clans extends JavaPlugin new FarmingShop(_clansManager, _clientManager, _donationManager); new TravelShop(_clansManager, _clientManager, _donationManager); new MiningShop(_clansManager, _clientManager, _donationManager); + new WorldManager(this); // Disable spigot item merging for (World world : getServer().getWorlds()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java index fb17f9fe5..006e4257e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java @@ -30,21 +30,63 @@ public class TutorialGettingStarted extends Tutorial { super(goldManager, taskManager, clansManager, donationManager, manager); - addTask(1, "Welcome", "Welcome to Clans! Before you start playing Clans, you need to create a Clan by typing {/c create [name]}! Don't worry though, at the end of this tutorial, you will be disbanding this clan. You will then be able to make a new clan, or join a friend's clan!"); - addTask(2, "Viewing Clan Info", "Now you can view information about your clan. To do this type {/c [name]}! You can also use any clan's name to get some information about them as well."); - addTask(3, "Leave Spawn", "Now you can leave the Spawn Island. Don't worry, you won’t get hurt from the fall! Once you end the tutorial, PvP will be enabled down there, so be careful!"); - addTask(4, "Go To The Wilderness", "Access your map with {/map} and head out into the wilderness! You’ll see various other locations marked on your map later."); - addTask(5, "Claiming Territory", "In order to claim a chunk of land for your clan you type {/c claim}! Keep in mind that you can only claim in the Wilderness, and not too close to other clan's claims and safe areas. Notice though, your clan runs on energy! You can buy energy from the shops!", "Good job! We won't claim this area just yet, you can do it again later when you find a nice location after the tutorial."); - addTask(6, "Visit The Shops", "At the shops you can buy most things you need! Once a day you can transfer 1000 gems to 5000 clans gold here as well!"); - addTask(7, "Use An Ability", "In order to use abilities you need a sword or axe. To use your sword ability, right click with your sword! To use your axe ability, right click with your axe!"); - addTask(8, "Class Customization", "To customize your class, right click an enchantment table! There you will find the GUI for all the skills in that class! Customize it to your liking!"); - addTask(9, "Disband Clan", "To disband your own clan, you can do {/c disband}, this will delete your clan, and you will be able to start a new one!"); + addTask(1, "Welcome", + "Welcome to Clans! " + + "To start playing Clans, you need to create a Clan by typing {/c create [Clan Name]}! " + + "Don't worry though, at the end of this tutorial, you will be deleting this clan."); + + addTask(2, "Viewing Clan Details", + "Now you can view information about your Clan. " + + "To do this type {/c [Clan Name]}! " + + "You can also use any Clans name to get some information about them as well."); + + addTask(3, "Leave Spawn Islands", + "Now you can leave the Spawn Island. " + + "Don't worry, you won't get hurt from the fall! " + + "Once you end the tutorial, PvP will be enabled down there, so be careful!"); + + addTask(4, "Go To The Wilderness", + "Use your Map (Slot 9) to help find your way to the Wilderness. " + + "The Wilderness is anywhere that is not colored on the Map. " + + "If you don't have a map, you can get one at any time by typing {/map}. " + + "You can zoom in/out by Left and Right Clicking!"); + + addTask(5, "Claim some Territory", + "Clans can claim 16x16 areas of Territory! " + + "Once claimed, only your Clan can break/place blocks here. " + + "This is the perfect place to build a base and stash your items!" + + "You can only claim in the Wilderness, and not next to other Clans Territory. " + + "Claim some Territory now, by typing {/c claim}! ", + + "Good job! We won't acutally claim this Territory yet!"); + + addTask(6, "Explore the Shops", + "You can buy all sorts of things at the Shops! " + + "You can also sell things to the Villagers for Gold! " + + "Look at your Map and take notice of where the Shops is. " + + "You can also transfer 1,000 Gems into 30,000 Clans Gold each day."); + + addTask(7, "Use a Class Ability", + "Find the PvP Gear shop, and Right-Click the Villager. " + + "Purchase Armor (all of the same type) and Sword from the PvP Shop. " + + "Then put on your Armor to equip a Champions Class. " + + "Right-Click with your Sword to use your Sword Ability!"); + + addTask(8, "Class Customization", + "To customize your Class, Right-Click an Enchantment Table! " + + "There should be one nearby in the Shops!" + + "Find it, and try customizing your Class! "); + + addTask(9, "Disband your Clan", + "Finally, let's disband your Clan to end the Tutorial. " + + "Simply type {/c disband} to do this. " + + "This will delete your Clan, and you'll be able to create or join a new one!"); _doScoreboard = true; _ghostMode = true; _startOnJoin = true; - _goldReward = 5000; - + _goldReward = 30000; + _uniqueId = "GettingStartedTutorial"; _friendlyName = "Getting Started"; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java new file mode 100644 index 000000000..ab47cdc8b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java @@ -0,0 +1,123 @@ +package mineplex.game.clans.world; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.UtilMath; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansManager; + +public class WorldManager extends MiniPlugin +{ + public WorldManager(JavaPlugin plugin) + { + super("Clan World Manager", plugin); + } + + @EventHandler + public void cullMobs(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW) + return; + + for (World world : getPlugin().getServer().getWorlds()) + { + HashMap> _ents = new HashMap>(); + + for (EntityType type : EntityType.values()) + _ents.put(type, new ArrayList()); + + for (Entity ent : world.getEntities()) + { + if (ent.getCustomName() == null) + _ents.get(ent.getType()).add(ent); + } + + for (EntityType type : _ents.keySet()) + { + ArrayList ents = _ents.get(type); + + //Clean Old Arrows + if (type == EntityType.ARROW) + { + for (Entity ent : ents) + if (ent.getTicksLived() > 800) + ent.remove(); + } + + //Animals + else if (type == EntityType.BAT) cull(ents, 50); + else if (type == EntityType.CHICKEN) cull(ents, 150); + else if (type == EntityType.COW) cull(ents, 150); + else if (type == EntityType.HORSE) cull(ents, 50); + else if (type == EntityType.IRON_GOLEM) cull(ents, 50); + else if (type == EntityType.MUSHROOM_COW) cull(ents, 50); + else if (type == EntityType.OCELOT) cull(ents, 50); + else if (type == EntityType.PIG) cull(ents, 150); + else if (type == EntityType.RABBIT) cull(ents, 50); + else if (type == EntityType.SHEEP) cull(ents, 150); + else if (type == EntityType.WOLF) cull(ents, 150); + + //Monster + else if (type == EntityType.CAVE_SPIDER) cull(ents, 100); + else if (type == EntityType.CREEPER) cull(ents, 100); + else if (type == EntityType.ENDERMAN) cull(ents, 50); + else if (type == EntityType.ENDERMITE) cull(ents, 50); + else if (type == EntityType.SILVERFISH) cull(ents, 50); + else if (type == EntityType.SKELETON) cull(ents, 100); + else if (type == EntityType.SLIME) cull(ents, 50); + else if (type == EntityType.SPIDER) cull(ents, 100); + else if (type == EntityType.ZOMBIE) cull(ents, 100); + + //Nether + else if (type == EntityType.BLAZE) cull(ents, 50); + else if (type == EntityType.GHAST) cull(ents, 50); + else if (type == EntityType.MAGMA_CUBE) cull(ents, 50); + else if (type == EntityType.PIG_ZOMBIE) cull(ents, 50); + + //Clean Old Minecarts + if (type == EntityType.MINECART || + type == EntityType.MINECART_CHEST || + type == EntityType.MINECART_COMMAND || + type == EntityType.MINECART_FURNACE || + type == EntityType.MINECART_HOPPER || + type == EntityType.MINECART_MOB_SPAWNER || + type == EntityType.MINECART_TNT) + { + for (Entity ent : ents) + if (ent.getTicksLived() > 800) + ent.remove(); + } + } + } + } + + public void cull(ArrayList ents, int limit) + { + int culled = 0; + EntityType type = null; + while (ents.size() > limit) + { + Entity ent = ents.remove(UtilMath.r(ents.size())); + + type = ent.getType(); + + ent.remove(); + + culled++; + } + + if (type != null) + { + System.out.println("Culled " + culled + " " + type); + } + } +} From b45eb53dffad9a69d5d55baa9a5e3b0038c8ab39 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 28 Nov 2015 00:43:01 +1100 Subject: [PATCH 2/3] remove old items --- .../src/mineplex/game/clans/world/WorldManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java index ab47cdc8b..3b579fd1a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java @@ -53,6 +53,14 @@ public class WorldManager extends MiniPlugin ent.remove(); } + //Clean Old Items + if (type == EntityType.ITEM) + { + for (Entity ent : ents) + if (ent.getTicksLived() > 2400) + ent.remove(); + } + //Animals else if (type == EntityType.BAT) cull(ents, 50); else if (type == EntityType.CHICKEN) cull(ents, 150); From def46c715eb7fb87f4ff4b3787f61048b7650273 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 28 Nov 2015 00:52:54 +1100 Subject: [PATCH 3/3] fixer --- .../src/mineplex/game/clans/world/WorldManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java index 3b579fd1a..408e33924 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/world/WorldManager.java @@ -54,7 +54,7 @@ public class WorldManager extends MiniPlugin } //Clean Old Items - if (type == EntityType.ITEM) + if (type == EntityType.DROPPED_ITEM) { for (Entity ent : ents) if (ent.getTicksLived() > 2400)