fixed bug with part 5 of the getting started tutorial (has to do with claiming events)

This commit is contained in:
NewGarbo 2015-11-09 08:45:34 +00:00
parent 8f507c4b9c
commit 4232a5675f
4 changed files with 53 additions and 21 deletions

View File

@ -615,7 +615,7 @@ public class ClansAdmin
clientClan.inform(caller.getName() + " claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName()); clientClan.inform(caller.getName() + " claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName());
} }
public void unclaim(Player caller, String args[]) public void unclaim(Player caller, String[] args)
{ {
if (args.length > 2) if (args.length > 2)
{ {

View File

@ -168,7 +168,13 @@ public class ClansCommand extends CommandBase<ClansManager>
private void help(Player caller) private void help(Player caller)
{ {
UtilServer.getServer().getPluginManager().callEvent(new ClansCommandExecutedEvent(caller, "help", null)); ClansCommandExecutedEvent event = new ClansCommandExecutedEvent(caller, "help");
UtilServer.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
UtilPlayer.message(caller, F.main("Clans", "Commands List;")); UtilPlayer.message(caller, F.main("Clans", "Commands List;"));
UtilPlayer.message(caller, F.help("/c create <clan>", "Create new Clan", Rank.ALL)); UtilPlayer.message(caller, F.help("/c create <clan>", "Create new Clan", Rank.ALL));
@ -825,10 +831,18 @@ public class ClansCommand extends CommandBase<ClansManager>
} }
} }
public void claim(Player caller, String args[]) public void claim(Player caller, String[] args)
{ {
ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller);
ClansCommandExecutedEvent event = new ClansCommandExecutedEvent(caller, "claim", args);
UtilServer.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
if (clan == null) if (clan == null)
{ {
UtilPlayer.message(caller, F.main("Clans", "You are not in a Clan.")); UtilPlayer.message(caller, F.main("Clans", "You are not in a Clan."));
@ -952,7 +966,13 @@ public class ClansCommand extends CommandBase<ClansManager>
if (!Recharge.Instance.use(caller, "Territory Claim", 60000, true, false)) return; if (!Recharge.Instance.use(caller, "Territory Claim", 60000, true, false)) return;
// Event // Event
PlayerClaimTerritoryEvent event = new PlayerClaimTerritoryEvent(caller, caller.getLocation().getChunk()); PlayerClaimTerritoryEvent claimEvent = new PlayerClaimTerritoryEvent(caller, caller.getLocation().getChunk());
UtilServer.getServer().getPluginManager().callEvent(claimEvent);
if (claimEvent.isCancelled())
{
return;
}
// Task // Task
Plugin.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false); Plugin.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false);
@ -982,7 +1002,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return (boxed >= req); return (boxed >= req);
} }
public void unclaim(Player caller, String args[]) public void unclaim(Player caller, String[] args)
{ {
if (args.length > 1) if (args.length > 1)
{ {
@ -1189,7 +1209,13 @@ public class ClansCommand extends CommandBase<ClansManager>
return; return;
} }
UtilServer.getServer().getPluginManager().callEvent(new ClansCommandExecutedEvent(caller, "info", search)); ClansCommandExecutedEvent event = new ClansCommandExecutedEvent(caller, "info", search);
UtilServer.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
{
return;
}
ClanInfo clan = Plugin.getClanUtility().searchClanPlayer(caller, search, true); ClanInfo clan = Plugin.getClanUtility().searchClanPlayer(caller, search, true);
if (clan == null) return; if (clan == null) return;

View File

@ -12,6 +12,8 @@ public class ClansCommandExecutedEvent extends Event
private String _command; private String _command;
private String[] _args; private String[] _args;
private boolean _cancelled;
public ClansCommandExecutedEvent(Player player, String command, String... args) public ClansCommandExecutedEvent(Player player, String command, String... args)
{ {
_player = player; _player = player;
@ -47,6 +49,11 @@ public class ClansCommandExecutedEvent extends Event
return _command; return _command;
} }
public boolean isCancelled()
{
return _cancelled;
}
public String[] getArguments() public String[] getArguments()
{ {
return _args; return _args;
@ -61,4 +68,9 @@ public class ClansCommandExecutedEvent extends Event
{ {
return handlers; return handlers;
} }
public void setCancelled(boolean cancelled)
{
_cancelled = cancelled;
}
} }

View File

@ -80,7 +80,6 @@ public class TutorialGettingStarted extends Tutorial
}, 40L); }, 40L);
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onClansShopButtonAdded(ClansShopAddButtonEvent event) public void onClansShopButtonAdded(ClansShopAddButtonEvent event)
{ {
@ -202,6 +201,14 @@ public class TutorialGettingStarted extends Tutorial
finishTask(event.getPlayer(), "Viewing Clan Info"); finishTask(event.getPlayer(), "Viewing Clan Info");
} }
} }
else if (event.getCommand().equals("claim"))
{
if (isInTutorial(event.getPlayer()) && get(event.getPlayer()).hasFinishedTask(getTask("Go To The Wilderness")) && !get(event.getPlayer()).hasFinishedTask(getTask("Claiming Territory")))
{
finishTask(event.getPlayer(), "Claiming Territory");
event.setCancelled(true);
}
}
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@ -224,19 +231,6 @@ public class TutorialGettingStarted extends Tutorial
} }
} }
@EventHandler(priority = EventPriority.MONITOR)
public boolean onClaim(final PlayerClaimTerritoryEvent event)
{
if (isInTutorial(event.getClaimer()) && get(event.getClaimer()).hasFinishedTask(getTask("Go To The Wilderness")) && !get(event.getClaimer()).hasFinishedTask(getTask("Claiming Territory")))
{
finishTask(event.getClaimer(), "Claiming Territory");
return false;
}
return true;
}
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onSkillTriggered(final SkillTriggerEvent event) public void onSkillTriggered(final SkillTriggerEvent event)
{ {
@ -294,5 +288,5 @@ public class TutorialGettingStarted extends Tutorial
{ {
UtilPlayer.message(player, F.main("Tutorials", "Welcome to the " + F.elem("Getting Started Tutorial!"))); UtilPlayer.message(player, F.main("Tutorials", "Welcome to the " + F.elem("Getting Started Tutorial!")));
} }
} }