diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java index 9430285fb..183e9ea30 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java @@ -125,9 +125,11 @@ public abstract class Objective implements L */ public final void leave(Player player) { + customLeave(player); + _active.remove(player.getUniqueId()); - customLeave(player); + getGoals().forEach(goal -> goal.leave(player)); } protected abstract void customLeave(Player player); diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java index d6942d892..c81ae3160 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java @@ -73,6 +73,20 @@ public abstract class ObjectiveGoal implements Listener protected abstract void customFinish(Player player); + protected void customLeave(Player player) { } + + protected void leave(Player player) + { + if (_active.contains(player.getUniqueId())) + { + System.out.println(String.format("Tutorial> [%s] left objective goal [%s]", player.getName(), getName(player))); + + _active.remove(player.getUniqueId()); + } + + customLeave(player); + } + protected void finish(Player player) { if (_active.contains(player.getUniqueId())) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java index 6fcb02004..1f7a68d4c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java @@ -87,6 +87,12 @@ public abstract class OrderedObjective extends Objective getBox(Block cornerA, Block cornerB) + { + if (cornerA == null || cornerB == null || (cornerA.getWorld() != cornerB.getWorld())) + return Collections.emptyList(); + + ArrayList list = new ArrayList<>(); + + int minX = Math.min(cornerA.getX(), cornerB.getX()); + int minY = Math.min(cornerA.getY(), cornerB.getY()); + int minZ = Math.min(cornerA.getZ(), cornerB.getZ()); + int maxX = Math.max(cornerA.getX(), cornerB.getX()); + int maxY = Math.max(cornerA.getY(), cornerB.getY()); + int maxZ = Math.max(cornerA.getZ(), cornerB.getZ()); + + for (int x = minX; x <= maxX; x++) + { + for (int y = minY; y <= maxY; y++) + { + for (int z = minZ; z <= maxZ; z++) + { + list.add(cornerA.getWorld().getBlockAt(x, y, z)); + } + } + } + + return list; + } + public static boolean inBoundingBox(Location loc, Location cornerA, Location cornerB) { if (loc.getX() <= Math.min(cornerA.getX(), cornerB.getX())) return false; 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 55d4d6022..0cfd172e9 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 @@ -37,6 +37,7 @@ 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.clans.event.ClansCommandPreExecutedEvent; import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.game.clans.spawn.Spawn; import net.minecraft.server.v1_8_R3.EnumDirection; @@ -59,6 +60,11 @@ public class ClansCommand extends CommandBase _clansManager.getClanShop().attemptShopOpen(caller); return; } + + ClansCommandPreExecutedEvent event = new ClansCommandPreExecutedEvent(caller, args); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) + return; if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("h")) help(caller); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansCommandPreExecutedEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansCommandPreExecutedEvent.java new file mode 100644 index 000000000..5c8695c35 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansCommandPreExecutedEvent.java @@ -0,0 +1,68 @@ +package mineplex.game.clans.clans.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ClansCommandPreExecutedEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private String[] _args; + + private boolean _cancelled; + + public ClansCommandPreExecutedEvent(Player player, String... args) + { + _player = player; + _args = args; + } + + public ClansCommandPreExecutedEvent(Player player, Object... args) + { + _player = player; + + String[] strArgs = new String[args != null ? args.length : 0]; + + int index = 0; + for (Object obj : args) + { + strArgs[index] = obj.toString(); + + index++; + } + + _args = strArgs; + } + + public Player getPlayer() + { + return _player; + } + + public boolean isCancelled() + { + return _cancelled; + } + + public String[] getArguments() + { + return _args; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java index 837d74103..7ff211498 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java @@ -2,6 +2,8 @@ package mineplex.game.clans.tutorial.tutorials.clans; import java.io.IOException; import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Stream; import org.bukkit.DyeColor; import org.bukkit.GameMode; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/FieldsObjective.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/FieldsObjective.java index 9aa26cb35..addb3cda5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/FieldsObjective.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/FieldsObjective.java @@ -17,7 +17,7 @@ public class FieldsObjective extends OrderedObjective addGoal(new GoToFieldsGoal(this)); // IMPLEMENTED addGoal(new MineDiamondsGoal(this)); // TODO: - addGoal(new KillZombiesGoal(this)); // IMPLEMENTED +// addGoal(new KillZombiesGoal(this)); // IMPLEMENTED } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java index c0f004618..e1b531fb2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java @@ -16,7 +16,7 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.fallingblock.FallingBlocks; +//import mineplex.core.fallingblock.FallingBlocks; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.weapon.Cannon; @@ -100,8 +100,8 @@ public class AttackEnemyGoal extends ObjectiveGoal { block.setType(Material.AIR); - if (block.getType() != Material.IRON_DOOR_BLOCK) - FallingBlocks.Instance.Spawn(block.getLocation(), block.getType(), block.getData(), center); +// if (block.getType() != Material.IRON_DOOR_BLOCK) +// FallingBlocks.Instance.Spawn(block.getLocation(), block.getType(), block.getData(), center); } }); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClaimLandGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClaimLandGoal.java index 08d00a90e..b7c717695 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClaimLandGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClaimLandGoal.java @@ -1,13 +1,20 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import mineplex.core.common.objective.Objective; import mineplex.core.common.objective.ObjectiveGoal; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.event.PlayerPreClaimTerritoryEvent; +import mineplex.game.clans.tutorial.TutorialRegion; import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial; import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective; @@ -26,6 +33,10 @@ public class ClaimLandGoal extends ObjectiveGoal @Override protected void customFinish(Player player) { + TutorialRegion region = getObjective().getPlugin().getRegion(player); + List blocks = region.getLocationMap().getGoldLocations(ClansMainTutorial.Bounds.LAND_CLAIM.getDataLocColor()); + UtilAlg.getBox(blocks.get(0).getBlock(), blocks.get(1).getBlock()).stream().filter(block -> block.getType() == Material.WOOL) + .forEach(block -> block.setType(Material.GLOWSTONE)); } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClanDetailsGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClanDetailsGoal.java index eeadc1de6..8d88ab556 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClanDetailsGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/ClanDetailsGoal.java @@ -30,7 +30,14 @@ public class ClanDetailsGoal extends ObjectiveGoal public String getDescription(Player player) { ClanInfo clan = ClansManager.getInstance().getClan(player); - return "View Clan Details with /c " + clan.getName(); + if (clan != null) + { + return "View Clan Details with /c " + clan.getName(); + } + else + { + return "View Clan Details"; + } } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/CreateClanGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/CreateClanGoal.java index 50cef6753..e7e8b42f3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/CreateClanGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/CreateClanGoal.java @@ -5,6 +5,7 @@ import org.bukkit.event.EventHandler; import mineplex.core.common.objective.Objective; import mineplex.core.common.objective.ObjectiveGoal; +import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.event.ClanCreatedEvent; import mineplex.game.clans.clans.event.ClanCreationCompleteEvent; import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective; @@ -20,6 +21,10 @@ public class CreateClanGoal extends ObjectiveGoal protected void customStart(Player player) { + if (ClansManager.getInstance().getClan(player) != null) + { + finish(player); + } } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java index ca69fc96f..23e0ff626 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/SetHomeGoal.java @@ -8,6 +8,7 @@ import mineplex.core.common.objective.ObjectiveGoal; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.event.ClanSetHomeEvent; +import mineplex.game.clans.clans.event.ClansCommandPreExecutedEvent; import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial; import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective; @@ -29,9 +30,9 @@ public class SetHomeGoal extends ObjectiveGoal } @EventHandler - public void onSetHome(ClanSetHomeEvent event) + public void onSetHome(ClansCommandPreExecutedEvent event) { - if (contains(event.getPlayer())) + if (contains(event.getPlayer()) && event.getArguments().length == 1 && event.getArguments()[0].equalsIgnoreCase("sethome")) { if (getObjective().getPlugin().isIn(event.getPlayer(), ClansMainTutorial.Bounds.LAND_CLAIM)) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/GoToFieldsGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/GoToFieldsGoal.java index f60747623..c9321881c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/GoToFieldsGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/GoToFieldsGoal.java @@ -1,15 +1,22 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.fields; +import java.util.UUID; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import mineplex.core.common.objective.Objective; import mineplex.core.common.objective.ObjectiveGoal; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent; +import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial; +import mineplex.game.clans.tutorial.tutorials.clans.objective.FieldsObjective; -public class GoToFieldsGoal extends ObjectiveGoal +public class GoToFieldsGoal extends ObjectiveGoal { - public GoToFieldsGoal(Objective objective) + public GoToFieldsGoal(FieldsObjective objective) { super(objective, "Go to the Fields", "Run to the center of the map, to the Fields"); } @@ -23,21 +30,20 @@ public class GoToFieldsGoal extends ObjectiveGoal protected void customFinish(Player player) { } - + @EventHandler - public void enterRegion(PlayerEnterTerritoryEvent event) + public void checkRegion(UpdateEvent event) { - if (!contains(event.getPlayer())) - { + if (event.getType() != UpdateType.FAST) return; - } - - // This "reverse" equals is to prevent an NPE - if (!"Fields".equals(event.getNewTerritory())) + + for (UUID uuid : getActivePlayers()) { - return; + Player player = UtilPlayer.searchExact(uuid); + if (getObjective().getPlugin().isIn(player, ClansMainTutorial.Bounds.FIELDS)) + { + finish(player); + } } - - finish(event.getPlayer()); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/MineDiamondsGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/MineDiamondsGoal.java index 4e8ceadfe..6360bc284 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/MineDiamondsGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/fields/MineDiamondsGoal.java @@ -1,27 +1,100 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.fields; +import java.util.HashMap; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.ItemStack; import mineplex.core.common.objective.Objective; import mineplex.core.common.objective.ObjectiveGoal; import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent; +import mineplex.game.clans.tutorial.TutorialRegion; +import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial; +import mineplex.game.clans.tutorial.tutorials.clans.objective.FieldsObjective; -public class MineDiamondsGoal extends ObjectiveGoal +public class MineDiamondsGoal extends ObjectiveGoal { - public MineDiamondsGoal(Objective objective) + private HashMap _playersMap; + + public MineDiamondsGoal(FieldsObjective objective) { super(objective, "Mine 10 diamonds", "Search for some diamonds in the Fields and mine them"); + + _playersMap = new HashMap<>(); } @Override protected void customStart(Player player) { + player.getInventory().addItem(new ItemStack(Material.DIAMOND_PICKAXE)); + + _playersMap.put(player.getUniqueId(), new AtomicInteger(0)); } @Override protected void customFinish(Player player) { + _playersMap.remove(player.getUniqueId()); + } + + @Override + protected void customLeave(Player player) + { + _playersMap.remove(player.getUniqueId()); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + if (!contains(event.getPlayer()) || event.getBlock().getType() != Material.DIAMOND_ORE) + return; + + TutorialRegion region = getObjective().getPlugin().getRegion(event.getPlayer()); + if (getObjective().getPlugin().isIn(event.getBlock().getLocation(), region, ClansMainTutorial.Bounds.FIELDS)) + { + event.setCancelled(true); + event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation().add(0.5, 0.5, 0.5), new ItemStack(Material.DIAMOND)); + event.getBlock().setType(Material.COBBLESTONE); + + Bukkit.getServer().getScheduler().runTaskLater(getObjective().getJavaPlugin(), new Runnable() + { + @Override + public void run() + { + if (contains(event.getPlayer())) + { + event.getBlock().setType(Material.DIAMOND_ORE); + } + } + }, 20 * 10); + } + } + + @EventHandler + public void onItemPickup(PlayerPickupItemEvent event) + { + if (!contains(event.getPlayer())) + return; + + if (event.getItem().getItemStack().getType() == Material.DIAMOND) + { + int count = _playersMap.get(event.getPlayer().getUniqueId()).getAndIncrement(); + if (count == 10) + finish(event.getPlayer()); + } + } + + @Override + public String getName(Player player) + { + int count = _playersMap.get(player.getUniqueId()).get(); + return "Mine Diamonds " + count + "/10"; } - }