Fixes for ben

This commit is contained in:
Shaun Bennett 2016-03-25 08:13:30 +11:00
parent f000360565
commit 85511b4c26
15 changed files with 255 additions and 24 deletions

View File

@ -125,9 +125,11 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> 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);

View File

@ -73,6 +73,20 @@ public abstract class ObjectiveGoal <T extends Objective> 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()))

View File

@ -87,6 +87,12 @@ public abstract class OrderedObjective<Plugin> extends Objective<Plugin, Ordered
setGoal(player, 0);
}
@Override
protected void customLeave(Player player)
{
}
private void setGoal(Player player, int index)
{
OrderedObjectiveData data = getData(player); // Should never be null!

View File

@ -2,11 +2,13 @@ package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Stream;
import org.bukkit.Location;
import org.bukkit.block.Block;
@ -168,6 +170,34 @@ public class UtilAlg
return element;
}
public static List<Block> getBox(Block cornerA, Block cornerB)
{
if (cornerA == null || cornerB == null || (cornerA.getWorld() != cornerB.getWorld()))
return Collections.emptyList();
ArrayList<Block> 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;

View File

@ -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>
_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);

View File

@ -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;
}
}

View File

@ -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;

View File

@ -17,7 +17,7 @@ public class FieldsObjective extends OrderedObjective<ClansMainTutorial>
addGoal(new GoToFieldsGoal(this)); // IMPLEMENTED
addGoal(new MineDiamondsGoal(this)); // TODO:
addGoal(new KillZombiesGoal(this)); // IMPLEMENTED
// addGoal(new KillZombiesGoal(this)); // IMPLEMENTED
}
@Override

View File

@ -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<ClanObjective>
{
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);
}
});

View File

@ -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<ClanObjective>
@Override
protected void customFinish(Player player)
{
TutorialRegion region = getObjective().getPlugin().getRegion(player);
List<Location> 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

View File

@ -30,7 +30,14 @@ public class ClanDetailsGoal extends ObjectiveGoal<ClanObjective>
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

View File

@ -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<ClanObjective>
protected void customStart(Player player)
{
if (ClansManager.getInstance().getClan(player) != null)
{
finish(player);
}
}
@Override

View File

@ -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<ClanObjective>
}
@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))
{

View File

@ -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<FieldsObjective>
{
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());
}
}

View File

@ -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<FieldsObjective>
{
public MineDiamondsGoal(Objective objective)
private HashMap<UUID, AtomicInteger> _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";
}
}