mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-02 06:28:52 +00:00
Prevent Teleport commands during raid
This commit is contained in:
1 parent
aca1a685aa
commit
8c413ba158
4 files changed
+104
-1
No files matched your search
@@ -2,6 +2,7 @@ package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.listeners.CommandsListener;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -198,6 +199,7 @@ public class Main extends JavaPlugin {
|
||||
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
|
||||
getCommand("raid").setTabCompleter(new RaidTabCompletion());
|
||||
getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new CommandsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new BlockBreakListener(), (Plugin) this);
|
||||
initData();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
@@ -183,6 +184,24 @@ public class Raid {
|
||||
"The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!");
|
||||
}
|
||||
|
||||
|
||||
//Prevent players from leaving gather town prematurely
|
||||
for (String playerName : getActiveRaiders()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if(!WorldCoord.parseWorldCoord(p).getTownBlock().getTown().equals(Raid.this.getGatherTown())) {
|
||||
Raid.this.removeActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "To rejoin, do /raid join [war] [town]");
|
||||
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Raid Travel phase behavior
|
||||
|
||||
@@ -14,10 +14,11 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RaidCommands implements CommandExecutor
|
||||
public class RaidCommands implements CommandExecutor
|
||||
{
|
||||
public static ArrayList<Town> towns;
|
||||
public static ArrayList<Raid> raids;
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandsListener implements Listener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onCommandSend(final PlayerCommandPreprocessEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
String[] args = event.getMessage().split(" ");
|
||||
|
||||
/*
|
||||
Prevent any teleport command events from occuring
|
||||
If using PlayerTeleportEvent, it breaks the death logic
|
||||
*/
|
||||
for(Raid raid : RaidCommands.raids) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if(raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) {
|
||||
//only do for active raiders and any defenders
|
||||
if(raid.getActiveRaiders().contains(p.getName()) || raid.getDefenders().contains(p.getName())) {
|
||||
if (args.length >= 2) {
|
||||
if (args[0].equalsIgnoreCase("/n") || args[0].equalsIgnoreCase("/nat") || args[0].equalsIgnoreCase("/nation")) {
|
||||
if (args[1].equalsIgnoreCase("spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/t") || args[0].equalsIgnoreCase("/town")) {
|
||||
if (args[1].equalsIgnoreCase("spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
if (args[0].equalsIgnoreCase("/home")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/tpa")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/tpahere")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/wild")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("/rtp")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user