mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
siege or raid check logic
This commit is contained in:
1 parent
df0a66d089
commit
18f32af4b2
1 file changed
+44
-38
@@ -18,12 +18,14 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerInteractListener implements Listener {
|
||||
|
||||
//map of broken doors
|
||||
public Map<Door, Long> brokenDoors;
|
||||
public Map<Door, Long> brokenDoors = new HashMap<Door, Long>() {
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -32,7 +34,7 @@ public class PlayerInteractListener implements Listener {
|
||||
* @author AubriTheHuman
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerKilled(final PlayerInteractEvent event) {
|
||||
public void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Action action = event.getAction();
|
||||
Block clicked = event.getClickedBlock();
|
||||
@@ -40,53 +42,57 @@ public class PlayerInteractListener implements Listener {
|
||||
|
||||
if (action == Action.LEFT_CLICK_BLOCK && clicked.getType().toString().contains("DOOR")) { // right click + any door types
|
||||
Door door = (Door) clicked.getBlockData();
|
||||
|
||||
boolean inSiegeOrRaid = false;
|
||||
//siege check
|
||||
for(Siege s : SiegeData.getSieges()) {
|
||||
for (TownBlock townBlock : s.getTown().getTownBlocks()) {
|
||||
if(WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
inSiegeOrRaid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//if it wasnt in a siege, then
|
||||
if(!inSiegeOrRaid) {
|
||||
for(Raid r : RaidData.getRaids()) {
|
||||
for (TownBlock townBlock : r.getRaidedTown().getTownBlocks()) {
|
||||
if(WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
inSiegeOrRaid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(inSiegeOrRaid) {
|
||||
// lock door in the opposite position
|
||||
if (item.getType() == Material.GUNPOWDER && item.getItemMeta().getDisplayName().contains("Door Ram")) {
|
||||
if (brokenDoors.get(door) != null && brokenDoors.get(door) > System.currentTimeMillis()) {
|
||||
player.sendMessage("The door is already broken!");
|
||||
|
||||
boolean inSiegeOrRaid = false;
|
||||
//siege check
|
||||
for(Siege s : SiegeData.getSieges()) {
|
||||
for (TownBlock townBlock : s.getTown().getTownBlocks()) {
|
||||
if(WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
inSiegeOrRaid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//if it wasnt in a siege, then
|
||||
if(!inSiegeOrRaid) {
|
||||
for(Raid r : RaidData.getRaids()) {
|
||||
for (TownBlock townBlock : r.getRaidedTown().getTownBlocks()) {
|
||||
if(WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
inSiegeOrRaid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(inSiegeOrRaid) {
|
||||
if (brokenDoors.get(door) != null && brokenDoors.get(door) > System.currentTimeMillis()) {
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("&cThe door is already broken!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("&eBreak it down alright!"));
|
||||
brokenDoors.put(door, System.currentTimeMillis() + (1000L * Main.getInstance().getConfig().getInt("batteringRamEffectiveness")));
|
||||
return;
|
||||
|
||||
} else {
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("&cThis item can only be used in a siege or raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage("Break it down alright!");
|
||||
brokenDoors.put(door, System.currentTimeMillis() + (1000L * Main.getInstance().getConfig().getInt("batteringRamEffectiveness")));
|
||||
return;
|
||||
}
|
||||
|
||||
if (brokenDoors.get(door) != null && brokenDoors.get(door) > System.currentTimeMillis()) {
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("Door is broken! " + String.valueOf(System.currentTimeMillis()) + " " + brokenDoors.get(door)));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(Helper.chatLabel() + Helper.color("&cThis item can only be used in a siege or raid!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user