| @@ -0,0 +1,240 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.*; | ||
| import org.simiancage.DeathTpPlus.models.TombStoneBlockDTP; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
|
|
||
| public class AdminCommandDTP implements CommandExecutor { | ||
|
|
||
| private static final String NO_TOMBSTONES_FOUND_FOR = "No tombstones found for "; | ||
| private static final String PERM_DENIED = "Permission Denied"; | ||
| private static final String INVALID_TOMBSTONE_ENTRY = "Invalid tombstone entry."; | ||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private DeathMessagesDTP deathMessages; | ||
| private TombMessagesDTP tombMessages; | ||
| private TombStoneHelperDTP tombStoneHelper; | ||
|
|
||
|
|
||
| public AdminCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| deathMessages = DeathMessagesDTP.getInstance(); | ||
| tombMessages = TombMessagesDTP.getInstance(); | ||
| tombStoneHelper = TombStoneHelperDTP.getInstance(); | ||
| log.error("dtpadmin command registered"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command cmd, String label, | ||
| String[] args) { | ||
| log.debug("dtpadmin command executing"); | ||
| if (!plugin.hasPerm(sender, "admin", false)) { | ||
| plugin.sendMessage(sender, PERM_DENIED); | ||
| return true; | ||
| } | ||
| Player p = (Player) sender; | ||
| if (args.length == 0) { | ||
| plugin.sendMessage(p, "Usage: /dtpadmin list"); | ||
| plugin.sendMessage(p, "Usage: /dtpadmin list <playerCaseSensitive>"); | ||
| plugin.sendMessage(p, | ||
| "Usage: /dtpadmin find <playerCaseSensitive> <#>"); | ||
| plugin.sendMessage(p, | ||
| "Usage: /dtpadmin remove <playerCaseSensitive> <#>"); | ||
| plugin.sendMessage(p, | ||
| "Usage: /dtpadmin time <playerCaseSensitive> <#>"); | ||
| plugin.sendMessage(p, "Usage: /dtpadmin version"); | ||
| return true; | ||
| } | ||
| if (args[0].equalsIgnoreCase("list")) { | ||
| if (!plugin.hasPerm(sender, "admin.list", false)) { | ||
| plugin.sendMessage(p, PERM_DENIED); | ||
| return true; | ||
| } | ||
| if (args.length < 2) { | ||
| if (tombStoneHelper.getPlayerTombStoneList().keySet().isEmpty()) { | ||
| plugin.sendMessage(p, "There are no tombstones."); | ||
| return true; | ||
| } | ||
| plugin.sendMessage(p, "Players with tombstones:"); | ||
| for (String player : tombStoneHelper.getPlayerTombStoneList().keySet()) { | ||
| plugin.sendMessage(p, player); | ||
| } | ||
| return true; | ||
| } | ||
| ArrayList<TombStoneBlockDTP> pList = tombStoneHelper.getPlayerTombStoneList(args[1]); | ||
| if (pList == null) { | ||
| plugin.sendMessage(p, NO_TOMBSTONES_FOUND_FOR + args[1] + "."); | ||
| return true; | ||
| } | ||
| plugin.sendMessage(p, "Tombstone List:"); | ||
| int i = 0; | ||
| for (TombStoneBlockDTP tombStoneDTP : pList) { | ||
| i++; | ||
| if (tombStoneDTP.getBlock() == null) { | ||
| continue; | ||
| } | ||
| int X = tombStoneDTP.getBlock().getX(); | ||
| int Y = tombStoneDTP.getBlock().getY(); | ||
| int Z = tombStoneDTP.getBlock().getZ(); | ||
| plugin.sendMessage(p, " " + i + " - World: " | ||
| + tombStoneDTP.getBlock().getWorld().getName() + " @(" + X | ||
| + "," + Y + "," + Z + ")"); | ||
| } | ||
| return true; | ||
| } else if (args[0].equalsIgnoreCase("find")) { | ||
| if (!plugin.hasPerm(sender, "admin.find", false)) { | ||
| plugin.sendMessage(p, PERM_DENIED); | ||
| return true; | ||
| } | ||
| ArrayList<TombStoneBlockDTP> pList = tombStoneHelper.getPlayerTombStoneList(args[1]); | ||
| if (pList == null) { | ||
| plugin.sendMessage(p, NO_TOMBSTONES_FOUND_FOR + args[1] + "."); | ||
| return true; | ||
| } | ||
| int slot = 0; | ||
| try { | ||
| slot = Integer.parseInt(args[2]); | ||
| } catch (Exception e) { | ||
| plugin.sendMessage(p, INVALID_TOMBSTONE_ENTRY); | ||
| return true; | ||
| } | ||
| slot -= 1; | ||
| if (slot < 0 || slot >= pList.size()) { | ||
| plugin.sendMessage(p, INVALID_TOMBSTONE_ENTRY); | ||
| return true; | ||
| } | ||
| TombStoneBlockDTP tStoneBlockDTP = pList.get(slot); | ||
| double degrees = (tombStoneHelper.getYawTo(tStoneBlockDTP.getBlock().getLocation(), | ||
| p.getLocation()) + 270) % 360; | ||
| int X = tStoneBlockDTP.getBlock().getX(); | ||
| int Y = tStoneBlockDTP.getBlock().getY(); | ||
| int Z = tStoneBlockDTP.getBlock().getZ(); | ||
| plugin.sendMessage(p, args[1] + "'s tombstone #" + args[2] | ||
| + " is at " + X + "," + Y + "," + Z + ", to the " | ||
| + tombStoneHelper.getDirection(degrees) + "."); | ||
| return true; | ||
| } else if (args[0].equalsIgnoreCase("time")) { | ||
| if (!plugin.hasPerm(p, "admin.time", false)) { | ||
| plugin.sendMessage(p, PERM_DENIED); | ||
| return true; | ||
| } | ||
| if (args.length != 3) { | ||
| return false; | ||
| } | ||
| ArrayList<TombStoneBlockDTP> pList = tombStoneHelper.getPlayerTombStoneList(args[1]); | ||
| if (pList == null) { | ||
| plugin.sendMessage(p, NO_TOMBSTONES_FOUND_FOR + args[1] + "."); | ||
| return true; | ||
| } | ||
| int slot = 0; | ||
| try { | ||
| slot = Integer.parseInt(args[2]); | ||
| } catch (Exception e) { | ||
| plugin.sendMessage(p, INVALID_TOMBSTONE_ENTRY); | ||
| return true; | ||
| } | ||
| slot -= 1; | ||
| if (slot < 0 || slot >= pList.size()) { | ||
| plugin.sendMessage(p, INVALID_TOMBSTONE_ENTRY); | ||
| return true; | ||
| } | ||
| long cTime = System.currentTimeMillis() / 1000; | ||
| TombStoneBlockDTP tStoneBlockDTP = pList.get(slot); | ||
| long secTimeLeft = (tStoneBlockDTP.getTime() + Long.parseLong(config.getRemoveTombStoneSecurityTimeOut())) | ||
| - cTime; | ||
| long remTimeLeft = (tStoneBlockDTP.getTime() + Long.parseLong(config.getRemoveTombStoneTime())) - cTime; | ||
| if (config.isRemoveTombStoneSecurity() && secTimeLeft > 0) { | ||
| plugin.sendMessage(p, "Security removal: " + secTimeLeft | ||
| + " seconds."); | ||
| } | ||
| if (config.isRemoveTombStone() & remTimeLeft > 0) { | ||
| plugin.sendMessage(p, "Tombstone removal: " + remTimeLeft | ||
| + " seconds."); | ||
| } | ||
| if (config.isKeepTombStoneUntilEmpty() || config.isRemoveTombStoneWhenEmpty()) { | ||
| plugin.sendMessage(p, "Keep until empty:" | ||
| + config.isKeepTombStoneUntilEmpty() + "; remove when empty: " | ||
| + config.isRemoveTombStoneWhenEmpty()); | ||
| } | ||
| return true; | ||
| } else if (args[0].equalsIgnoreCase("version")) { | ||
| String message; | ||
| if (config.isDifferentPluginAvailable()) { | ||
| message = "There is a different plugin version available, please check the logs."; | ||
| } else { | ||
| message = "Your plugin version is fine"; | ||
| } | ||
| plugin.sendMessage(p, message); | ||
|
|
||
| if (!(config.getConfigVer().equalsIgnoreCase(config.getConfigCurrent()))) { | ||
| plugin.sendMessage(p, "Your config file is out of date."); | ||
| } else if (config.getConfigVer().equalsIgnoreCase(config.getConfigCurrent())) { | ||
| plugin.sendMessage(p, "Your config file is up to date."); | ||
| } | ||
|
|
||
| if (deathMessages.isDeathMessagesRequiresUpdate()) { | ||
| message = "Your deathmessages are out of date."; | ||
| } else { | ||
| message = "Your deathmessages are up to date."; | ||
| } | ||
| plugin.sendMessage(p, message); | ||
|
|
||
| if (tombMessages.isTombMessagesRequiresUpdate()) { | ||
| message = "Your tombmessages are out of date."; | ||
| } else { | ||
| message = "Your tombmessages are up to date."; | ||
| } | ||
| plugin.sendMessage(p, message); | ||
|
|
||
|
|
||
| } else if (args[0].equalsIgnoreCase("remove")) { | ||
| if (!plugin.hasPerm(sender, "admin.remove", false)) { | ||
| plugin.sendMessage(p, PERM_DENIED); | ||
| return true; | ||
| } | ||
| ArrayList<TombStoneBlockDTP> pList = tombStoneHelper.getPlayerTombStoneList(args[1]); | ||
| if (pList == null) { | ||
| plugin.sendMessage(p, NO_TOMBSTONES_FOUND_FOR + args[1] + "."); | ||
| return true; | ||
| } | ||
| int slot = 0; | ||
| try { | ||
| slot = Integer.parseInt(args[2]); | ||
| } catch (Exception e) { | ||
| plugin.sendMessage(p, INVALID_TOMBSTONE_ENTRY); | ||
| return true; | ||
| } | ||
| slot -= 1; | ||
| if (slot < 0 || slot >= pList.size()) { | ||
| plugin.sendMessage(p, INVALID_TOMBSTONE_ENTRY); | ||
| return true; | ||
| } | ||
| TombStoneBlockDTP tStoneBlockDTP = pList.get(slot); | ||
| tombStoneHelper.destroyTombStone(tStoneBlockDTP); | ||
|
|
||
| } else { | ||
| plugin.sendMessage(p, "Usage: /dtpadmin list"); | ||
| plugin.sendMessage(p, "Usage: /dtpadmin list <playerCaseSensitive>"); | ||
| plugin.sendMessage(p, | ||
| "Usage: /dtpadmin find <playerCaseSensitive> <#>"); | ||
| plugin.sendMessage(p, | ||
| "Usage: /dtpadmin remove <playerCaseSensitive> <#>"); | ||
| plugin.sendMessage(p, | ||
| "Usage: /dtpadmin time <playerCaseSensitive> <#>"); | ||
| plugin.sendMessage(p, "Usage: /dtpadmin version"); | ||
| return true; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,92 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.logs.DeathLogDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathRecordDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathRecordDTP.DeathRecordType; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: DeathsCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:10 | ||
| */ | ||
|
|
||
| public class DeathsCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private DeathLogDTP deathLog; | ||
|
|
||
| public DeathsCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| deathLog = plugin.getDeathLog(); | ||
| log.error("deaths command registered"); | ||
| } | ||
|
|
||
| public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
| log.debug("deaths command executing"); | ||
| boolean canUseCommand = false; | ||
| if (sender instanceof Player) { | ||
| Player player = (Player) sender; | ||
| // ToDo remove permission compability in 3.2 | ||
| if (player.hasPermission("deathtpplus.deathtp.deaths") || player.hasPermission("deathtpplus.deaths")) { | ||
| canUseCommand = true; | ||
| if (player.hasPermission("deathtpplus.deaths")) { | ||
| log.warning("old permission found: deathtpplus.deaths for player " + player.getName()); | ||
| log.warning("please use: deathtpplus.deathtp.deaths"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (canUseCommand) { | ||
|
|
||
| int total; | ||
|
|
||
| if (args.length > 2) { | ||
| return false; | ||
| } | ||
|
|
||
| switch (args.length) { | ||
| case 0: | ||
| Player player = (Player) sender; | ||
| total = plugin.getDeathLog().getTotalByType(player.getName(), DeathRecordType.death); | ||
| if (total > -1) { | ||
| sender.sendMessage(String.format("You died %d time(s)", total)); | ||
| } else { | ||
| sender.sendMessage("No record found."); | ||
| } | ||
| break; | ||
| case 1: | ||
| total = plugin.getDeathLog().getTotalByType(args[0], DeathRecordType.death); | ||
| if (total > -1) { | ||
| sender.sendMessage(String.format("%s died %d time(s)", args[0], total)); | ||
| } else { | ||
| sender.sendMessage("No record found."); | ||
| } | ||
| break; | ||
| case 2: | ||
| DeathRecordDTP record = plugin.getDeathLog().getRecordByType(args[0], args[1], DeathRecordType.death); | ||
| if (record != null) { | ||
| sender.sendMessage(String.format("%s died by %s %d time(s)", args[0], args[1], record.getCount())); | ||
| } else { | ||
| sender.sendMessage("No record found."); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| return true; | ||
|
|
||
| } | ||
| } | ||
|
|
| @@ -0,0 +1,244 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.World; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.logs.DeathLocationsLogDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathLocationRecordDTP; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: DeathtpCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:09 | ||
| */ | ||
|
|
||
| public class DeathtpCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private DeathLocationsLogDTP deathLocationLog; | ||
| /** | ||
| * List of blocks which are normally save to teleport into | ||
| */ | ||
| private List<Integer> saveBlocks = new ArrayList<Integer>(Arrays.asList(new Integer[]{ | ||
| 0, 6, 8, 9, 10, 11, 37, 38, 39, 40, 50, 51, 55, 59, 69, 76 | ||
| })); | ||
|
|
||
| public DeathtpCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| deathLocationLog = plugin.getDeathLocationLog(); | ||
| log.error("deathtp command registered"); | ||
| } | ||
|
|
||
| public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
| boolean canUseCommand = false; | ||
| boolean worldTravel = false; | ||
| log.debug("deathtp command executing"); | ||
|
|
||
|
|
||
| if (sender instanceof Player) { | ||
| Player player = (Player) sender; | ||
| // ToDo remove permission compability in 3.2 | ||
| canUseCommand = (player.hasPermission("deathtpplus.deathtp") || player.hasPermission("deathtpplus.deathtp.deathtp") || config.isAllowDeathtp()); | ||
|
|
||
| if (player.hasPermission("deathtpplus.deathtp")) { | ||
| log.warning("old permission found: deathtpplus.deathtp for player " + player.getName()); | ||
| log.warning("please use: deathtpplus.deathtp.deathtp"); | ||
| } | ||
|
|
||
| if (canUseCommand) { | ||
| log.debug("canUseCommand", canUseCommand); | ||
| String thisWorld = player.getWorld().getName(); | ||
| if ((player.hasPermission("deathtpplus.worldtravel") && config.getAllowWorldTravel().equalsIgnoreCase("permissions")) || config.getAllowWorldTravel().equalsIgnoreCase("yes")) { | ||
| worldTravel = true; | ||
| } | ||
| if (!canTp(player)) { | ||
| log.debug("canTp", "nope"); | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| DeathLocationRecordDTP locationRecord = deathLocationLog.getRecord(player.getName()); | ||
|
|
||
| if (locationRecord != null) { | ||
| log.debug("locationRecord", locationRecord); | ||
| Location deathLocation; | ||
| World deathWorld = player.getServer().getWorld(locationRecord.getWorldName()); | ||
| if (config.isTeleportToHighestBlock()) { | ||
| deathLocation = deathWorld.getHighestBlockAt(locationRecord.getLocation().getBlockX(), locationRecord.getLocation().getBlockZ()).getLocation(); | ||
| } else { | ||
| deathLocation = saveDeathLocation(locationRecord, deathWorld); | ||
| if (deathLocation == null) { | ||
| player.sendRawMessage("There is no save place to teleport you at location:"); | ||
| player.sendRawMessage("x: " + locationRecord.getLocation().getX() + " y: " + locationRecord.getLocation().getY() + " z: " + locationRecord.getLocation().getZ() + " in world: " + locationRecord.getWorldName()); | ||
| player.sendRawMessage("Have fun walking... sorry about that.."); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| // Added chunkload when chunk not loaded, code from Tele++ | ||
|
|
||
| if (!deathWorld.isChunkLoaded(deathLocation.getBlockX() >> 4, deathLocation.getBlockZ() >> 4)) { | ||
| deathWorld.loadChunk(deathLocation.getBlockX() >> 4, deathLocation.getBlockZ() >> 4); | ||
| } | ||
|
|
||
| if (!thisWorld.equals(deathWorld.getName())) { | ||
| if (worldTravel) { | ||
| deathLocation.setWorld(deathWorld); | ||
| player.teleport(deathLocation); | ||
| registerTp(player); | ||
| } else { | ||
| player.sendMessage("You do not have the right to travel between worlds via deathtp!"); | ||
| } | ||
| } else { | ||
| player.teleport(deathLocation); | ||
| registerTp(player); | ||
| } | ||
| } | ||
|
|
||
| } else { | ||
| player.sendMessage("That command is not available"); | ||
| } | ||
|
|
||
|
|
||
| return true; | ||
| } else { | ||
| log.warning("This is only a player command."); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| private Boolean canTp(Player player) { | ||
| return hasItem(player) && hasFunds(player); | ||
| } | ||
|
|
||
| private void registerTp(Player player) { | ||
| if (hasItem(player)) { | ||
| if (Integer.parseInt(config.getChargeItem()) != 0) { | ||
| ItemStack itemInHand = player.getItemInHand(); | ||
|
|
||
| if (itemInHand.getAmount() == 1) { | ||
| player.getInventory().clear(player.getInventory().getHeldItemSlot()); | ||
| } else { | ||
| itemInHand.setAmount(itemInHand.getAmount() - 1); | ||
| player.setItemInHand(itemInHand); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (hasFunds(player)) { | ||
| if (plugin.isEconomyActive()) { | ||
| double deathTpCost = Double.valueOf(config.getDeathtpCost().trim()); | ||
| plugin.getEconomy().withdrawPlayer(player.getName(), deathTpCost); | ||
| player.sendMessage(String.format("You used %s to use /deathtp.", plugin.getEconomy().format(deathTpCost))); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private Boolean hasItem(Player player) { | ||
| int chargeItem = Integer.parseInt(config.getChargeItem()); | ||
| log.debug("chargeItem", chargeItem); | ||
| // costs item in inventory | ||
| if (chargeItem == 0 || chargeItem == player.getItemInHand().getType().getId()) { | ||
| log.debug("hasItem", true); | ||
| return true; | ||
| } | ||
|
|
||
| player.sendMessage(String.format("You must be holding a %s to teleport.", Material.getMaterial(chargeItem).toString().toLowerCase())); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private Boolean hasFunds(Player player) { | ||
| double deathTpCost = Double.valueOf(config.getDeathtpCost().trim()); | ||
| log.debug("deathTpCost", deathTpCost); | ||
| if (deathTpCost == 0) { | ||
| return true; | ||
| } | ||
|
|
||
| // costs economy | ||
| if (plugin.isEconomyActive()) { | ||
| log.debug("isEconomyActive", "yes"); | ||
| if (plugin.getEconomy().getBalance(player.getName()) > deathTpCost) { | ||
| log.debug("hasFunds", true); | ||
| return true; | ||
| } else { | ||
| player.sendMessage(String.format("You need %s coins to use /deathtp.", plugin.getEconomy().format(deathTpCost))); | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| // Code from Tele++ | ||
| private Location saveDeathLocation(DeathLocationRecordDTP locationRecord, World world) { | ||
| log.debug("world", world); | ||
| double x = locationRecord.getLocation().getBlockX(); | ||
| double y = locationRecord.getLocation().getBlockY(); | ||
| double z = locationRecord.getLocation().getBlockZ(); | ||
| log.debug("x,y,z:", x + "," + y + "," + z); | ||
|
|
||
| x = x + .5D; | ||
| z = z + .5D; | ||
|
|
||
| if (y < 1.0D) { | ||
| y = 1.0D; | ||
| } | ||
|
|
||
| while (blockIsAboveAir(world, x, y, z)) { | ||
| y -= 1.0D; | ||
|
|
||
| if (y < -512) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| while (!blockIsSafe(world, x, y, z)) { | ||
| y += 1.0D; | ||
|
|
||
| if (y > 512) { | ||
| return null; | ||
| } | ||
| } | ||
| Location saveDeathLocation = new Location(world, x, y, z); | ||
| log.debug("saveDeathLocation", saveDeathLocation); | ||
| return saveDeathLocation; | ||
| } | ||
|
|
||
| private boolean blockIsAboveAir(World world, double x, double y, double z) { | ||
| Material mat = world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1.0D), (int) Math.floor(z)).getType(); | ||
|
|
||
| return saveBlocks.contains(mat.getId()); | ||
| } | ||
|
|
||
| public boolean blockIsSafe(Block block) { | ||
| return blockIsSafe(block.getWorld(), block.getX(), block.getY(), block.getZ()); | ||
| } | ||
|
|
||
| public boolean blockIsSafe(World world, double x, double y, double z) { | ||
| Material mat1 = world.getBlockAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)).getType(); | ||
| Material mat2 = world.getBlockAt((int) Math.floor(x), (int) Math.floor(y + 1.0D), (int) Math.floor(z)).getType(); | ||
|
|
||
| return (saveBlocks.contains(mat1.getId())) && (saveBlocks.contains(mat2.getId())); | ||
| } | ||
|
|
||
| } | ||
|
|
| @@ -0,0 +1,82 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: FindCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:04 | ||
| */ | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.TombStoneHelperDTP; | ||
| import org.simiancage.DeathTpPlus.models.TombStoneBlockDTP; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class FindCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private TombStoneHelperDTP tombStoneHelper; | ||
|
|
||
| public FindCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| tombStoneHelper = TombStoneHelperDTP.getInstance(); | ||
| log.error("dtpfind command registered"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command cmd, String label, | ||
| String[] args) { | ||
| log.debug("dtpfind command executing"); | ||
| if (!plugin.hasPerm(sender, "tombstone.find", false)) { | ||
| plugin.sendMessage(sender, "Permission Denied"); | ||
| return true; | ||
| } | ||
| if (args.length != 1) { | ||
| return false; | ||
| } | ||
| ArrayList<TombStoneBlockDTP> pList = tombStoneHelper.getPlayerTombStoneList(sender.getName()); | ||
| if (pList == null) { | ||
| plugin.sendMessage(sender, "You have no tombstones."); | ||
| return true; | ||
| } | ||
| int slot = 0; | ||
| Player p = (Player) sender; | ||
| try { | ||
| slot = Integer.parseInt(args[0]); | ||
| } catch (Exception e) { | ||
| plugin.sendMessage(sender, "Invalid tombstone"); | ||
| return true; | ||
| } | ||
| slot -= 1; | ||
| if (slot < 0 || slot >= pList.size()) { | ||
| plugin.sendMessage(sender, "Invalid tombstone"); | ||
| return true; | ||
| } | ||
| TombStoneBlockDTP tStoneBlockDTP = pList.get(slot); | ||
| double degrees = (tombStoneHelper.getYawTo(tStoneBlockDTP.getBlock().getLocation(), | ||
| p.getLocation()) + 270) % 360; | ||
| p.setCompassTarget(tStoneBlockDTP.getBlock().getLocation()); | ||
| plugin.sendMessage( | ||
| sender, | ||
| "Your tombstone #" | ||
| + args[0] | ||
| + " is to the " | ||
| + tombStoneHelper.getDirection(degrees) | ||
| + ". Your compass has been set to point at its location. Use /dtpreset to reset it to your spawn point."); | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
|
|
| @@ -0,0 +1,90 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.logs.DeathLogDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathRecordDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathRecordDTP.DeathRecordType; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: KillsCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:09 | ||
| */ | ||
|
|
||
| public class KillsCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private DeathLogDTP deathLog; | ||
|
|
||
| public KillsCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| deathLog = plugin.getDeathLog(); | ||
| log.error("kills command registered"); | ||
|
|
||
| } | ||
|
|
||
| public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
| log.debug("kills command executing"); | ||
| boolean canUseCommand = false; | ||
| if (sender instanceof Player) { | ||
| Player player = (Player) sender; | ||
| // ToDo remove permission compability in 3.2 | ||
| canUseCommand = player.hasPermission("deathtpplus.kills") || player.hasPermission("deathtpplus.deathtp.kills"); | ||
| if (player.hasPermission("deathtpplus.kills")) { | ||
| log.warning("old permission found: deathtpplus.kills for player " + player.getName()); | ||
| log.warning("please use: deathtpplus.deathtp.kills"); | ||
| } | ||
| } | ||
|
|
||
| if (canUseCommand) { | ||
|
|
||
| int total; | ||
|
|
||
| if (args.length > 2) { | ||
| return false; | ||
| } | ||
|
|
||
| switch (args.length) { | ||
| case 0: | ||
| Player player = (Player) sender; | ||
| total = deathLog.getTotalByType(player.getName(), DeathRecordType.kill); | ||
| if (total > -1) { | ||
| sender.sendMessage(String.format("You have %d kill(s)", total)); | ||
| } else { | ||
| sender.sendMessage("No record found."); | ||
| } | ||
| break; | ||
| case 1: | ||
| total = deathLog.getTotalByType(args[0], DeathRecordType.kill); | ||
| if (total > -1) { | ||
| sender.sendMessage(String.format("%s has %d kill(s)", args[0], total)); | ||
| } else { | ||
| sender.sendMessage("No record found."); | ||
| } | ||
| break; | ||
| case 2: | ||
| DeathRecordDTP record = deathLog.getRecordByType(args[0], args[1], DeathRecordType.kill); | ||
| if (record != null) { | ||
| sender.sendMessage(String.format("%s killed %s %d time(s)", args[0], args[1], record.getCount())); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return true; | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,68 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: ListCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:07 | ||
| */ | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.TombStoneHelperDTP; | ||
| import org.simiancage.DeathTpPlus.models.TombStoneBlockDTP; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class ListCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private TombStoneHelperDTP tombStoneHelper; | ||
|
|
||
| public ListCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| tombStoneHelper = TombStoneHelperDTP.getInstance(); | ||
| log.error("dtplist command registered"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command cmd, String label, | ||
| String[] args) { | ||
| log.debug("dtplist command executing"); | ||
| if (!plugin.hasPerm(sender, "tombstone.list", false)) { | ||
| plugin.sendMessage(sender, "Permission Denied"); | ||
| return true; | ||
| } | ||
| ArrayList<TombStoneBlockDTP> pList = tombStoneHelper.getPlayerTombStoneList(sender.getName()); | ||
| if (pList == null) { | ||
| plugin.sendMessage(sender, "You have no tombstones."); | ||
| return true; | ||
| } | ||
| plugin.sendMessage(sender, "Tombstone List:"); | ||
| int i = 0; | ||
| for (TombStoneBlockDTP tombStoneDTP : pList) { | ||
| i++; | ||
| if (tombStoneDTP.getBlock() == null) { | ||
| continue; | ||
| } | ||
| int X = tombStoneDTP.getBlock().getX(); | ||
| int Y = tombStoneDTP.getBlock().getY(); | ||
| int Z = tombStoneDTP.getBlock().getZ(); | ||
| plugin.sendMessage(sender, " " + i + " - World: " | ||
| + tombStoneDTP.getBlock().getWorld().getName() + " @(" + X + "," | ||
| + Y + "," + Z + ")"); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
|
|
| @@ -0,0 +1,46 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: ResetCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:07 | ||
| */ | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
|
|
||
| public class ResetCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
|
|
||
| public ResetCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| log.error("dtpreset command registered"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command cmd, String label, | ||
| String[] args) { | ||
| log.debug("dtpreset command executing"); | ||
| if (!plugin.hasPerm(sender, "tombstone.reset", false)) { | ||
| plugin.sendMessage(sender, "Permission Denied"); | ||
| return true; | ||
| } | ||
| Player p = (Player) sender; | ||
| p.setCompassTarget(p.getWorld().getSpawnLocation()); | ||
| plugin.sendMessage(sender, "Your compass has been reset to the spawn location!"); | ||
| return true; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,81 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.logs.StreakLogDTP; | ||
| import org.simiancage.DeathTpPlus.models.StreakRecordDTP; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: StreakCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:10 | ||
| */ | ||
|
|
||
| public class StreakCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private StreakLogDTP streakLog; | ||
|
|
||
| public StreakCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| streakLog = plugin.getStreakLog(); | ||
| log.error("streak command registered"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | ||
| log.debug("streak command executing"); | ||
| boolean canUseCommand = false; | ||
| if (sender instanceof Player) { | ||
| Player player = (Player) sender; | ||
| // ToDo remove permission compability in 3.2 | ||
| canUseCommand = player.hasPermission("deathtpplus.streak") || player.hasPermission("deathtpplus.deathtp.streak"); | ||
| if (player.hasPermission("deathtpplus.streak")) { | ||
| log.warning("old permission found: deathtpplus.streak for player " + player.getName()); | ||
| log.warning("please use: deathtpplus.deathtp.streak"); | ||
| } | ||
| } | ||
|
|
||
| if (canUseCommand) { | ||
| if (config.isShowStreaks()) { | ||
|
|
||
| StreakRecordDTP streak = plugin.getStreakLog().getRecord(args.length > 0 ? args[0] : ((Player) sender).getName()); | ||
|
|
||
| if (streak != null) { | ||
| if (streak.getCount() < 0) { | ||
| if (args.length > 0) { | ||
| sender.sendMessage(String.format("%s is on a %d death streak.", args[0], streak.getCount() * -1)); | ||
| } else { | ||
| sender.sendMessage(String.format("You are on a %d death streak.", streak.getCount() * -1)); | ||
| } | ||
| } else { | ||
| if (args.length > 0) { | ||
| sender.sendMessage(String.format("%s is on a %d kill streak.", args[0], streak.getCount())); | ||
| } else { | ||
| sender.sendMessage(String.format("You are on a %d kill streak.", streak.getCount())); | ||
| } | ||
| } | ||
| } else { | ||
| sender.sendMessage("No record found."); | ||
| } | ||
|
|
||
|
|
||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| return false; | ||
| } | ||
| } |
| @@ -0,0 +1,100 @@ | ||
| package org.simiancage.DeathTpPlus.commands; | ||
|
|
||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.TombStoneHelperDTP; | ||
| import org.simiancage.DeathTpPlus.models.TombStoneBlockDTP; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: TimeCommandDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:08 | ||
| */ | ||
|
|
||
| public class TimeCommandDTP implements CommandExecutor { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private TombStoneHelperDTP tombStoneHelper; | ||
|
|
||
| public TimeCommandDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| tombStoneHelper = TombStoneHelperDTP.getInstance(); | ||
| log.error("dtptime command registered"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean onCommand(CommandSender sender, Command cmd, String label, | ||
| String[] args) { | ||
| log.debug("dpttime command executing"); | ||
| if (!plugin.hasPerm(sender, "tombstone.time", false)) { | ||
| plugin.sendMessage(sender, "Permission Denied"); | ||
| return true; | ||
| } | ||
| Player p = (Player) sender; | ||
| if (args.length != 1) { | ||
| return false; | ||
| } | ||
| ArrayList<TombStoneBlockDTP> pList = tombStoneHelper.getPlayerTombStoneList(p.getName()); | ||
| if (pList == null) { | ||
| plugin.sendMessage(p, "You have no Tombstones."); | ||
| return true; | ||
| } | ||
| int slot = 0; | ||
| try { | ||
| slot = Integer.parseInt(args[0]); | ||
| } catch (Exception e) { | ||
| plugin.sendMessage(p, "Invalid Tombstone"); | ||
| return true; | ||
| } | ||
| slot -= 1; | ||
| if (slot < 0 || slot >= pList.size()) { | ||
| plugin.sendMessage(p, "Invalid Tombstone"); | ||
| return true; | ||
| } | ||
| long cTime = System.currentTimeMillis() / 1000; | ||
| TombStoneBlockDTP tStoneBlockDTP = pList.get(slot); | ||
| long secTimeLeft = (tStoneBlockDTP.getTime() + Long.parseLong(config.getRemoveTombStoneSecurityTimeOut())) - cTime; | ||
| long remTimeLeft = (tStoneBlockDTP.getTime() + Long.parseLong(config.getRemoveTombStoneTime())) - cTime; | ||
|
|
||
| if (config.isRemoveTombStoneSecurity() && secTimeLeft > 0) { | ||
| plugin.sendMessage(p, | ||
| "Security will be removed from your Tombstone in " | ||
| + secTimeLeft + " seconds."); | ||
| } | ||
|
|
||
| if (config.isRemoveTombStone() & remTimeLeft > 0) { | ||
| plugin.sendMessage(p, "Your Tombstone will break in " + remTimeLeft | ||
| + " seconds"); | ||
| } | ||
| if (config.isRemoveTombStoneWhenEmpty() && config.isKeepTombStoneUntilEmpty()) { | ||
| plugin.sendMessage( | ||
| p, | ||
| "Break override: Your Tombstone will break when it is emptied, but will not break until then."); | ||
| } else { | ||
| if (config.isRemoveTombStoneWhenEmpty()) { | ||
| plugin.sendMessage(p, | ||
| "Break override: Your Tombstone will break when it is emptied."); | ||
| } | ||
| if (config.isKeepTombStoneUntilEmpty()) { | ||
| plugin.sendMessage(p, | ||
| "Break override: Your Tombstone will not break until it is empty."); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,62 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.Event; | ||
|
|
||
| /** | ||
| * PluginName: ${plugin} | ||
| * Class: DeathStreakEventDTP | ||
| * User: DonRedhorse | ||
| * Date: 25.11.11 | ||
| * Time: 19:46 | ||
| */ | ||
|
|
||
| @SuppressWarnings("serial") | ||
| public class DeathStreakEventDTP extends Event { | ||
| private Player player; | ||
| private Player killer; | ||
| private String message; | ||
| private Integer deaths; | ||
|
|
||
| public DeathStreakEventDTP(Player player, Player killer, String message, Integer deaths) { | ||
| super("DeathStreakEventDTP"); | ||
|
|
||
| this.player = player; | ||
| this.killer = killer; | ||
| this.message = message; | ||
| this.deaths = deaths; | ||
| } | ||
|
|
||
| public Player getPlayer() { | ||
| return player; | ||
| } | ||
|
|
||
| public void setPlayer(Player player) { | ||
| this.player = player; | ||
| } | ||
|
|
||
| public Player getKiller() { | ||
| return killer; | ||
| } | ||
|
|
||
| public void setKiller(Player killer) { | ||
| this.killer = killer; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
|
|
||
| public void setMessage(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public Integer getDeaths() { | ||
| return deaths; | ||
| } | ||
|
|
||
| public void setDeaths(Integer deaths) { | ||
| this.deaths = deaths; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,62 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.Event; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: KillStreakEventDTP | ||
| * User: DonRedhorse | ||
| * Date: 25.11.11 | ||
| * Time: 19:53 | ||
| */ | ||
|
|
||
| @SuppressWarnings("serial") | ||
| public class KillStreakEventDTP extends Event { | ||
| private Player player; | ||
| private Player victim; | ||
| private String message; | ||
| private Integer kills; | ||
|
|
||
| public KillStreakEventDTP(Player player, Player victim, String message, Integer kills) { | ||
| super("KillStreakEventDTP"); | ||
|
|
||
| this.player = player; | ||
| this.victim = victim; | ||
| this.message = message; | ||
| this.kills = kills; | ||
| } | ||
|
|
||
| public Player getPlayer() { | ||
| return player; | ||
| } | ||
|
|
||
| public void setPlayer(Player player) { | ||
| this.player = player; | ||
| } | ||
|
|
||
| public Player getVictim() { | ||
| return victim; | ||
| } | ||
|
|
||
| public void setVictim(Player victim) { | ||
| this.victim = victim; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
|
|
||
| public void setMessage(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public Integer getKills() { | ||
| return kills; | ||
| } | ||
|
|
||
| public void setKills(Integer kills) { | ||
| this.kills = kills; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,149 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.block.Sign; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.block.BlockBreakEvent; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.TombStoneHelperDTP; | ||
| import org.simiancage.DeathTpPlus.models.TombStoneBlockDTP; | ||
| import org.simiancage.DeathTpPlus.objects.TombDTP; | ||
| import org.simiancage.DeathTpPlus.workers.TombWorkerDTP; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: onBlockBreakDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.11.11 | ||
| * Time: 20:32 | ||
| */ | ||
|
|
||
| public class onBlockBreakDTP { | ||
|
|
||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private DeathTpPlus plugin; | ||
| private TombWorkerDTP tombWorker; | ||
| private TombStoneHelperDTP tombStoneHelper; | ||
|
|
||
| public onBlockBreakDTP() { | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| tombWorker = TombWorkerDTP.getInstance(); | ||
| tombStoneHelper = TombStoneHelperDTP.getInstance(); | ||
| } | ||
|
|
||
| public void oBBTombStone(DeathTpPlus plugin, BlockBreakEvent event) { | ||
|
|
||
| log.debug("onBlockBreak TombStone executing"); | ||
| Block b = event.getBlock(); | ||
| Player p = event.getPlayer(); | ||
|
|
||
| if (b.getType() == Material.WALL_SIGN) { | ||
| org.bukkit.material.Sign signData = (org.bukkit.material.Sign) b | ||
| .getState().getData(); | ||
| TombStoneBlockDTP tStoneBlockDTP = tombStoneHelper.getTombStoneBlockList(b.getRelative( | ||
| signData.getAttachedFace()).getLocation()); | ||
| if (tStoneBlockDTP == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (tStoneBlockDTP.getLocketteSign() != null) { | ||
| Sign sign = (Sign) b.getState(); | ||
| event.setCancelled(true); | ||
| sign.update(); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (b.getType() != Material.CHEST && b.getType() != Material.SIGN_POST) { | ||
| return; | ||
| } | ||
|
|
||
| TombStoneBlockDTP tStoneBlockDTP = tombStoneHelper.getTombStoneBlockList(b.getLocation()); | ||
|
|
||
| if (tStoneBlockDTP == null) { | ||
| return; | ||
| } | ||
| Location location = b.getLocation(); | ||
| String loc = location.getWorld().getName(); | ||
| loc = loc + ", x=" + location.getBlock().getX(); | ||
| loc = loc + ", y=" + location.getBlock().getY(); | ||
| loc = loc + ", z=" + location.getBlock().getZ(); | ||
| if (!config.isAllowTombStoneDestroy() && !plugin.hasPerm(p, "admin", false)) { | ||
|
|
||
| log.debug(p.getName() + " tried to destroy tombstone at " | ||
| + loc); | ||
| plugin.sendMessage(p, "Tombstone unable to be destroyed"); | ||
| event.setCancelled(true); | ||
| return; | ||
| } | ||
|
|
||
| if (plugin.getLwcPlugin() != null && config.isEnableLWC() | ||
| && tStoneBlockDTP.getLwcEnabled()) { | ||
| if (tStoneBlockDTP.getOwner().equals(p.getName()) | ||
| || plugin.hasPerm(p, "admin", false)) { | ||
| tombStoneHelper.deactivateLWC(tStoneBlockDTP, true); | ||
| } else { | ||
| event.setCancelled(true); | ||
| return; | ||
| } | ||
| } | ||
| log.debug(p.getName() + " destroyed tombstone at " | ||
| + loc); | ||
| tombStoneHelper.removeTombStone(tStoneBlockDTP, true); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| public void oBBTomb(BlockBreakEvent event) { | ||
|
|
||
| log.debug("onBlockBreak Tomb executing"); | ||
| Block block = event.getBlock(); | ||
| Player player = event.getPlayer(); | ||
|
|
||
| if (block.getState() instanceof Sign) { | ||
| String playerName = event.getPlayer().getName(); | ||
| Sign sign = (Sign) block.getState(); | ||
| if (sign.getLine(0).indexOf(config.getTombKeyWord()) == 0) { | ||
| TombDTP TombDTP; | ||
| if (player.hasPermission("deathtpplus.admin.tomb")) { | ||
| if ((TombDTP = tombWorker.getTomb(block)) != null) { | ||
| TombDTP.removeSignBlock(block); | ||
| if (config.isResetTombRespawn()) { | ||
| TombDTP.setRespawn(null); | ||
| player.sendMessage( | ||
| tombWorker.graveDigger + TombDTP.getPlayer() | ||
| + "'s respawn point has been reset."); | ||
| } | ||
| } | ||
| return; | ||
| } | ||
| if (tombWorker.hasTomb(playerName)) { | ||
| if (!tombWorker.getTomb(playerName).hasSign(block)) { | ||
| event.setCancelled(true); | ||
| } else { | ||
| TombDTP = tombWorker.getTomb(playerName); | ||
| TombDTP.removeSignBlock(block); | ||
| if (config.isResetTombRespawn()) { | ||
| TombDTP.setRespawn(null); | ||
| player.sendMessage( | ||
| tombWorker.graveDigger + TombDTP.getPlayer() | ||
| + "'s respawn point has been reset."); | ||
| } | ||
| } | ||
| } else { | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } |
| @@ -0,0 +1,15 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: onEntityExplodeDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.11.11 | ||
| * Time: 20:29 | ||
| */ | ||
|
|
||
| public class onEntityExplodeDTP { | ||
| // ToDO move the code | ||
|
|
||
| } | ||
|
|
| @@ -0,0 +1,15 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: onPlayerInteractDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.11.11 | ||
| * Time: 20:29 | ||
| */ | ||
|
|
||
| public class onPlayerInteractDTP { | ||
|
|
||
| // ToDo move the code.... | ||
| } | ||
|
|
| @@ -0,0 +1,15 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: onPlayerJoinDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.11.11 | ||
| * Time: 20:30 | ||
| */ | ||
|
|
||
| public class onPlayerJoinDTP { | ||
|
|
||
| // ToDo move the code | ||
| } | ||
|
|
| @@ -0,0 +1,16 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: onPlayerRespawnDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.11.11 | ||
| * Time: 20:31 | ||
| */ | ||
|
|
||
| public class onPlayerRespawnDTP { | ||
|
|
||
| //ToDo Move the code | ||
| //ToDo Implement Allow WordTravel | ||
| } | ||
|
|
| @@ -0,0 +1,113 @@ | ||
| package org.simiancage.DeathTpPlus.events; | ||
|
|
||
| import org.bukkit.block.Block; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.block.SignChangeEvent; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.objects.TombDTP; | ||
| import org.simiancage.DeathTpPlus.workers.TombWorkerDTP; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: onSignChangeDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.11.11 | ||
| * Time: 20:33 | ||
| */ | ||
|
|
||
| public class onSignChangeDTP { | ||
|
|
||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private DeathTpPlus plugin; | ||
| private TombWorkerDTP tombWorkerDTP; | ||
|
|
||
| public onSignChangeDTP() { | ||
| this.log = LoggerDTP.getLogger(); | ||
| this.config = ConfigDTP.getInstance(); | ||
| this.tombWorkerDTP = TombWorkerDTP.getInstance(); | ||
| } | ||
|
|
||
| public void oSCTomb(SignChangeEvent event) { | ||
| log.debug("onSignChange Tomb executing"); | ||
| String line0 = event.getLine(0); | ||
| Player p = event.getPlayer(); | ||
| boolean admin = false; | ||
| if (line0.indexOf(config.getTombKeyWord()) == 0) { | ||
| if (!event.getLine(1).isEmpty() && p.hasPermission("deathtpplus.admin.tomb")) { | ||
| admin = true; | ||
| } | ||
| // Sign check | ||
| TombDTP TombDTP = null; | ||
| String deadName = event.getLine(1); | ||
| if (admin) { | ||
| if ((TombDTP = tombWorkerDTP.getTomb(deadName)) == null) { | ||
| try { | ||
| deadName = p.getServer().getPlayer(event.getLine(1)).getName(); | ||
| } catch (Exception e2) { | ||
| p.sendMessage(tombWorkerDTP.graveDigger + "The player " + event.getLine(1) | ||
| + "was not found.(The player HAS to be CONNECTED)"); | ||
| return; | ||
| } | ||
| } else { | ||
| deadName = TombDTP.getPlayer(); | ||
| } | ||
| } else { | ||
| deadName = event.getPlayer().getName(); | ||
| } | ||
| log.debug("deadName", deadName); | ||
| if (TombDTP != null) { | ||
| TombDTP.checkSigns(); | ||
| } else if (tombWorkerDTP.hasTomb(deadName)) { | ||
| TombDTP = tombWorkerDTP.getTomb(deadName); | ||
| TombDTP.checkSigns(); | ||
| } | ||
| int nbSign = 0; | ||
| if (TombDTP != null) { | ||
| nbSign = TombDTP.getNbSign(); | ||
| } | ||
| // max check | ||
| int maxTombs = config.getMaxTomb(); | ||
| if (!admin && maxTombs != 0 && (nbSign + 1) > maxTombs) { | ||
| p.sendMessage(tombWorkerDTP.graveDigger + "You have reached your Tomb limit."); | ||
| event.setCancelled(true); | ||
| return; | ||
| } | ||
| // perm and economy check | ||
| if ((!admin && !p.hasPermission("deathtpplus.tomb.create")) | ||
| || !tombWorkerDTP.economyCheck(p, "creation-price")) { | ||
| event.setCancelled(true); | ||
| return; | ||
| } | ||
| Block block = event.getBlock(); | ||
| try { | ||
|
|
||
| if (TombDTP != null) { | ||
| TombDTP.setPlayer(deadName); | ||
| TombDTP.addSignBlock(block); | ||
| } else { | ||
| TombDTP = new TombDTP(block); | ||
| TombDTP.setPlayer(deadName); | ||
| tombWorkerDTP.setTomb(deadName, TombDTP); | ||
| } | ||
| TombDTP.updateNewBlock(); | ||
| if (config.isUseTombAsRespawnPoint()) { | ||
| TombDTP.setRespawn(p.getLocation()); | ||
| if (admin) { | ||
| p.sendMessage(tombWorkerDTP.graveDigger + " When " + deadName | ||
| + " die, he/she will respawn here."); | ||
| } else { | ||
| p.sendMessage(tombWorkerDTP.graveDigger + " When you die you'll respawn here."); | ||
| } | ||
| } | ||
| } catch (IllegalArgumentException e2) { | ||
| p.sendMessage(tombWorkerDTP.graveDigger | ||
| + "It's not a good place for a Tomb. Try somewhere else."); | ||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,301 @@ | ||
| package org.simiancage.DeathTpPlus.helpers; | ||
| /** | ||
| * | ||
| * PluginName: DeathTpPlus | ||
| * Class: LoggerDTP | ||
| * User: DonRedhorse | ||
| * Date: 10.11.11 | ||
| * Time: 14:13 | ||
| * | ||
| */ | ||
|
|
||
| import org.bukkit.plugin.Plugin; | ||
|
|
||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
|
|
||
| /** | ||
| * The LoggerDTP Class allows you to log in an easy way to the craftbukkit console. | ||
| * It supports different log levels:<p> | ||
| * {@link #info(String) info} <p> | ||
| * {@link #warning(String) warning} <p> | ||
| * {@link #severe(String) severe} <p> | ||
| * {@link #debug(String, Object) debug} <p> | ||
| * {@link #error(String) error} <p> | ||
| * {@link #log(java.util.logging.Level, String, Throwable) log}<p> | ||
| * and checks with the {@link ConfigDTP} if debug and error logging is | ||
| * enabled.<p> | ||
| * It also supports a plugin {@link #enableMsg()} and {@link #disableMsg()}.<p> | ||
| * Initialization of the LoggerDTP is being done by {@link #getInstance(String, String)} getInstance} .<p> | ||
| * Based on the work of xZise. | ||
| * | ||
| * @author Don Redhorse | ||
| * @author xZise | ||
| */ | ||
| @SuppressWarnings({"WeakerAccess", "UnusedDeclaration"}) | ||
| public class LoggerDTP { | ||
| /** | ||
| * Reference to the logger | ||
| */ | ||
| private final Logger logger; | ||
| /** | ||
| * contains the plugin name | ||
| */ | ||
| private final String pluginName; | ||
| /** | ||
| * contains the plugin pluginVersion | ||
| */ | ||
| private final String pluginVersion; | ||
| /** | ||
| * Instance of the LoggerDTP | ||
| */ | ||
| private static LoggerDTP instance = null; | ||
|
|
||
|
|
||
| /** | ||
| * Instance of the ConfigurationCalls | ||
| */ | ||
| private final ConfigDTP config = ConfigDTP.getInstance(); | ||
|
|
||
|
|
||
| /** | ||
| * Method to get the instance of the LoggerDTP. | ||
| * LoggerDTP will be initialized when necessary. | ||
| * | ||
| * @param loggerName should be "Minecraft" | ||
| * @param pluginName the pluginname as string | ||
| * | ||
| * @return instance of the LoggerDTP | ||
| */ | ||
| public static LoggerDTP getInstance(String loggerName, String pluginName) { | ||
| if (instance == null) { | ||
| instance = new LoggerDTP(loggerName, pluginName); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Method to get the instance of the LoggerDTP. | ||
| * LoggerDTP will be initialized when necessary. | ||
| * | ||
| * @param pluginName the pluginname as string | ||
| * | ||
| * @return instance of the LoggerDTP | ||
| */ | ||
| public static LoggerDTP getInstance(String pluginName) { | ||
| if (instance == null) { | ||
| instance = new LoggerDTP(pluginName); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Method to get the instance of the LoggerDTP. | ||
| * LoggerDTP will be initialized when necessary. | ||
| * Use this to initialize the LoggerDTP. | ||
| * | ||
| * @param pluginName the pluginname as Plugin | ||
| * | ||
| * @return instance of the LoggerDTP | ||
| */ | ||
| public static LoggerDTP getInstance(Plugin pluginName) { | ||
| if (instance == null) { | ||
| instance = new LoggerDTP(pluginName); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Method to get the instance of the LoggerDTP. | ||
| * Output to console via System.out.print if this method is called | ||
| * when instance is NULL | ||
| * | ||
| * @return instance of the LoggerDTP, NOTE: This can be NULL | ||
| */ | ||
| public static LoggerDTP getLogger() { | ||
| if (instance == null) { | ||
| System.out.print("LoggerDTP is not ready yet!"); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor to initialize the LoggerDTP via LoggerName and PluginName. | ||
| * will hand over to {@link #LoggerDTP(java.util.logging.Logger, String, String)} | ||
| * | ||
| * @param loggerName should be "Minecraft" | ||
| * @param pluginName the name of the plugin | ||
| */ | ||
| private LoggerDTP(String loggerName, String pluginName) { | ||
| this(Logger.getLogger(loggerName), pluginName, ""); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Constructor to initialize the LoggerDTP via the PluginName. | ||
| * will hand over to {@link #LoggerDTP(String, String)} | ||
| * | ||
| * @param pluginName the name of the plugin | ||
| */ | ||
| private LoggerDTP(String pluginName) { | ||
| this("Minecraft", pluginName); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Constructor which finally initializes the LoggerDTP. | ||
| * | ||
| * @param logger Logger object of Minecraft | ||
| * @param pluginName the name of the plugin | ||
| * @param version the version of the plugin | ||
| */ | ||
|
|
||
| private LoggerDTP(Logger logger, String pluginName, String version) { | ||
| this.logger = logger; | ||
| this.pluginName = pluginName; | ||
| this.pluginVersion = version; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Constructor to initialize the LoggerDTP via a Plugin Object. | ||
| * will hand over to {@link #LoggerDTP(java.util.logging.Logger, String, String)} | ||
| * | ||
| * @param plugin the plugin object | ||
| */ | ||
| private LoggerDTP(Plugin plugin) { | ||
| this(plugin.getServer().getLogger(), plugin.getDescription().getName(), plugin.getDescription().getVersion()); | ||
| } | ||
|
|
||
| // Nothing to change from here on.... | ||
| // *************************************************************************************************************************** | ||
|
|
||
| /** | ||
| * will output with INFO level to console if debugging is enabled and also prints out the object contents. | ||
| * | ||
| * @param msg message to output | ||
| * @param object object to output, will use .toString() | ||
| */ | ||
| public void debug(String msg, Object object) { | ||
| if (config.isDebugLogEnabled()) { | ||
| String objectMsg; | ||
| if (object == null) { | ||
| objectMsg = "null"; | ||
| } else { | ||
| objectMsg = object.toString(); | ||
| } | ||
| this.logger.info(this.formatMessage(msg + "= [" + objectMsg + "]")); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * will output with INFO level to console if debugging is enabled. | ||
| * | ||
| * @param msg message to output | ||
| */ | ||
| public void debug(String msg) { | ||
| if (config.isDebugLogEnabled()) { | ||
| this.logger.info(this.formatMessage(msg)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * formats the message by adding the [PluginName] in front. | ||
| * | ||
| * @param message to format, e.g. this is a test | ||
| * | ||
| * @return formated message, e.g. [PluginName] this is a test | ||
| */ | ||
| private String formatMessage(String message) { | ||
| return "[" + pluginName + "] " + message; | ||
| } | ||
|
|
||
| /** | ||
| * will output with INFO level to console if error logging is enabled | ||
| * | ||
| * @param msg message to output | ||
| */ | ||
| public void info(String msg) { | ||
| this.logger.info(this.formatMessage(msg)); | ||
| } | ||
|
|
||
| /** | ||
| * will output with WARN level to console | ||
| * | ||
| * @param msg message to output | ||
| */ | ||
| public void warning(String msg) { | ||
| this.logger.warning(this.formatMessage(msg)); | ||
| } | ||
|
|
||
| /** | ||
| * will output with SEVERE level to console | ||
| * | ||
| * @param msg message to output | ||
| */ | ||
| public void severe(String msg) { | ||
| this.logger.severe(this.formatMessage(msg)); | ||
| } | ||
|
|
||
| /** | ||
| * will output with SEVERE level to console and also prints the exception | ||
| * | ||
| * @param msg message to output | ||
| * @param exception exception to output | ||
| */ | ||
| public void severe(String msg, Throwable exception) { | ||
| this.log(Level.SEVERE, this.formatMessage(msg), exception); | ||
| } | ||
|
|
||
| /** | ||
| * will output with specified level to console | ||
| * | ||
| * @param level LoggerLevel = INFO, WARNING, SEVERE | ||
| * @param msg message to output | ||
| * @param exception exception to output | ||
| */ | ||
| public void log(Level level, String msg, Throwable exception) { | ||
| this.logger.log(level, this.formatMessage(msg), exception); | ||
| } | ||
|
|
||
| /** | ||
| * will output with WARNING level to console and also prints exception | ||
| * | ||
| * @param msg message to output | ||
| * @param exception exception to output | ||
| */ | ||
| public void warning(String msg, Throwable exception) { | ||
| this.log(Level.WARNING, this.formatMessage(msg), exception); | ||
| } | ||
|
|
||
| /** | ||
| * will output [PluginName] v "VersionNumber" enabled to console | ||
| */ | ||
| public void enableMsg() { | ||
| this.info("v" + this.pluginVersion + " enabled"); | ||
| } | ||
|
|
||
| /** | ||
| * will output [PluginName] v "VersionNumber" disabled to console | ||
| */ | ||
| public void disableMsg() { | ||
| this.info("v" + this.pluginVersion + " disabled"); | ||
| } | ||
|
|
||
| /** | ||
| * will output with INFO level to console if error logging is enabled | ||
| * | ||
| * @param msg message to output | ||
| */ | ||
| public void error(String msg) { | ||
| if (config.isErrorLogEnabled()) { | ||
| this.logger.info(msg); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
| @@ -0,0 +1,94 @@ | ||
| package org.simiancage.DeathTpPlus.helpers; | ||
|
|
||
| /** | ||
| * PluginName: ${plugin} | ||
| * Class: TombSaveSystemDTP | ||
| * User: DonRedhorse | ||
| * Date: 14.11.11 | ||
| * Time: 20:39 | ||
| */ | ||
|
|
||
| import org.simiancage.DeathTpPlus.logs.TombLogDTP; | ||
| import org.simiancage.DeathTpPlus.objects.TombDTP; | ||
|
|
||
| import java.io.*; | ||
| import java.util.HashMap; | ||
|
|
||
|
|
||
| public class TombSaveSystemDTP { | ||
| private String path; | ||
|
|
||
| public TombSaveSystemDTP(String path) { | ||
| this.path = path; | ||
| File dir = new File(path); | ||
| if (!dir.exists()) { | ||
| dir.mkdir(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Save all the tombs to the file tombs.dat | ||
| * | ||
| * @param toBeSaved | ||
| */ | ||
| public void save(HashMap<String, TombDTP> toBeSaved) { | ||
| File saveFile = new File(this.path + File.separator + "tombs.dat"); | ||
| if (!saveFile.exists()) { | ||
| try { | ||
| saveFile.createNewFile(); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| HashMap<String, TombLogDTP> toWrite = new HashMap<String, TombLogDTP>(); | ||
| for (String name : toBeSaved.keySet()) { | ||
| toWrite.put(name, toBeSaved.get(name).save()); | ||
| } | ||
|
|
||
| try { | ||
| FileOutputStream fos = new FileOutputStream(saveFile); | ||
| ObjectOutputStream out = new ObjectOutputStream(fos); | ||
| out.writeObject(toWrite); | ||
| out.close(); | ||
| } catch (IOException ex) { | ||
| ex.printStackTrace(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public HashMap<String, TombDTP> load() { | ||
| HashMap<String, TombDTP> result = new HashMap<String, TombDTP>(); | ||
| HashMap<String, TombLogDTP> saved = null; | ||
| File saveFile = new File(this.path + File.separator + "tombs.dat"); | ||
| if (!saveFile.exists()) { | ||
| return new HashMap<String, TombDTP>(); | ||
| } | ||
|
|
||
| FileInputStream fis = null; | ||
| ObjectInputStream in = null; | ||
|
|
||
| try { | ||
| fis = new FileInputStream(saveFile); | ||
| in = new ObjectInputStream(fis); | ||
| saved = (HashMap<String, TombLogDTP>) in.readObject(); | ||
| in.close(); | ||
| } catch (IOException ex) { | ||
| ex.printStackTrace(); | ||
| } catch (ClassNotFoundException ex) { | ||
| ex.printStackTrace(); | ||
| } | ||
| if (saved == null) { | ||
| return new HashMap<String, TombDTP>(); | ||
| } | ||
| for (String name : saved.keySet()) { | ||
| result.put(name, saved.get(name).load()); | ||
| } | ||
|
|
||
| return result; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
| @@ -0,0 +1,85 @@ | ||
| package org.simiancage.DeathTpPlus.helpers; | ||
|
|
||
| import org.bukkit.entity.*; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: UtilsDTP | ||
| * User: DonRedhorse | ||
| * Date: 25.11.11 | ||
| * Time: 19:17 | ||
| */ | ||
|
|
||
| public class UtilsDTP { | ||
| public static String convertColorCodes(String msg) { | ||
| return msg.replaceAll("&([0-9a-fA-F])", "§$1"); | ||
| } | ||
|
|
||
| public static String removeColorCodes(String msg) { | ||
| return msg.replaceAll("§[0-9a-fA-F]", ""); | ||
| } | ||
|
|
||
| public static CreatureType getCreatureType(Entity entity) { | ||
| if (entity instanceof CaveSpider) { | ||
| return CreatureType.CAVE_SPIDER; | ||
| } | ||
| if (entity instanceof Chicken) { | ||
| return CreatureType.CHICKEN; | ||
| } | ||
| if (entity instanceof Cow) { | ||
| return CreatureType.COW; | ||
| } | ||
| if (entity instanceof Creeper) { | ||
| return CreatureType.CREEPER; | ||
| } | ||
| if (entity instanceof Enderman) { | ||
| return CreatureType.ENDERMAN; | ||
| } | ||
| if (entity instanceof Ghast) { | ||
| return CreatureType.GHAST; | ||
| } | ||
| if (entity instanceof Giant) { | ||
| return CreatureType.GIANT; | ||
| } | ||
| if (entity instanceof Pig) { | ||
| return CreatureType.PIG; | ||
| } | ||
| if (entity instanceof PigZombie) { | ||
| return CreatureType.PIG_ZOMBIE; | ||
| } | ||
| if (entity instanceof Sheep) { | ||
| return CreatureType.SHEEP; | ||
| } | ||
| if (entity instanceof Skeleton) { | ||
| return CreatureType.SKELETON; | ||
| } | ||
| if (entity instanceof Slime) { | ||
| return CreatureType.SLIME; | ||
| } | ||
| if (entity instanceof Silverfish) { | ||
| return CreatureType.SILVERFISH; | ||
| } | ||
| if (entity instanceof Spider) { | ||
| return CreatureType.SPIDER; | ||
| } | ||
| if (entity instanceof Squid) { | ||
| return CreatureType.SQUID; | ||
| } | ||
| if (entity instanceof Zombie) { | ||
| return CreatureType.ZOMBIE; | ||
| } | ||
| if (entity instanceof Wolf) { | ||
| return CreatureType.WOLF; | ||
| } | ||
|
|
||
| // Monster is a parent class and needs to be last | ||
| if (entity instanceof Monster) { | ||
| return CreatureType.MONSTER; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
| @@ -0,0 +1,63 @@ | ||
| package org.simiancage.DeathTpPlus.listeners; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: BlockListenerDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 21:59 | ||
| */ | ||
|
|
||
| import org.bukkit.event.block.BlockBreakEvent; | ||
| import org.bukkit.event.block.BlockListener; | ||
| import org.bukkit.event.block.SignChangeEvent; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.events.onBlockBreakDTP; | ||
| import org.simiancage.DeathTpPlus.events.onSignChangeDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
|
|
||
| public class BlockListenerDTP extends BlockListener { | ||
|
|
||
| private DeathTpPlus plugin; | ||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private onBlockBreakDTP obb; | ||
| private onSignChangeDTP oss; | ||
|
|
||
| public BlockListenerDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| log.debug("BlockListener active"); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBlockBreak(BlockBreakEvent event) { | ||
|
|
||
| if (config.isEnableTombStone() && !event.isCancelled()) { | ||
| obb = new onBlockBreakDTP(); | ||
| obb.oBBTombStone(plugin, event); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| if (config.isEnableTomb() && !event.isCancelled()) { | ||
| obb = new onBlockBreakDTP(); | ||
| obb.oBBTomb(event); | ||
|
|
||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| public void onSignChange(SignChangeEvent event) { | ||
|
|
||
| if (config.isEnableTomb() && !event.isCancelled()) { | ||
| oss = new onSignChangeDTP(); | ||
| oss.oSCTomb(event); | ||
|
|
||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,82 @@ | ||
| package org.simiancage.DeathTpPlus.listeners; | ||
|
|
||
| //java imports | ||
|
|
||
| import org.bukkit.block.Block; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.entity.EntityDeathEvent; | ||
| import org.bukkit.event.entity.EntityExplodeEvent; | ||
| import org.bukkit.event.entity.EntityListener; | ||
| import org.bukkit.event.entity.PlayerDeathEvent; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.events.onEntityDeathDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.TombStoneHelperDTP; | ||
| import org.simiancage.DeathTpPlus.models.TombStoneBlockDTP; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| //bukkit imports | ||
|
|
||
| public class EntityListenerDTP extends EntityListener { | ||
| private DeathTpPlus plugin; | ||
| private ArrayList<String> lastDamageType = new ArrayList<String>(); | ||
| private String beforedamage = ""; | ||
| private PlayerDeathEvent playerDeathEvent = null; | ||
|
|
||
| private ConfigDTP config; | ||
| private LoggerDTP log; | ||
| private onEntityDeathDTP oedea; | ||
| private EntityListenerDTP instance; | ||
| private TombStoneHelperDTP tombStoneHelper; | ||
|
|
||
| public EntityListenerDTP(DeathTpPlus plugin) { | ||
| this.plugin = plugin; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| tombStoneHelper = TombStoneHelperDTP.getInstance(); | ||
| log.debug("EntityListener active"); | ||
| instance = this; | ||
| } | ||
|
|
||
|
|
||
| public void onEntityDeath(EntityDeathEvent event) { | ||
|
|
||
| if (event.getEntity() instanceof Player) { | ||
|
|
||
| if (plugin.isMobArenaEnabled()) { | ||
| plugin.getMaHandler().inRegion(event.getEntity().getLocation()); | ||
| log.debug("Player in MobArena Region"); | ||
| return; | ||
| } | ||
| if (config.isEnableDeathtp()) { | ||
| oedea = new onEntityDeathDTP(plugin); | ||
| oedea.oEDeaDeathTp(plugin, instance, event); | ||
| } | ||
|
|
||
| if (config.isShowDeathNotify() || config.isShowStreaks() || config.isAllowDeathLog() || config.isEnableTombStone() || config.isEnableTomb()) { | ||
| oedea = new onEntityDeathDTP(plugin); | ||
| oedea.oEDeaGeneralDeath(plugin, instance, event); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public void onEntityExplode(EntityExplodeEvent event) { | ||
| log.debug("onEntityExplodeDTP executing"); | ||
| if (event.isCancelled()) { | ||
| return; | ||
| } | ||
| if (!config.isCreeperProtection()) { | ||
| return; | ||
| } | ||
| for (Block block : event.blockList()) { | ||
| TombStoneBlockDTP tStoneBlockDTP = tombStoneHelper.getTombStoneBlockList(block.getLocation()); | ||
| if (tStoneBlockDTP != null) { | ||
| event.setCancelled(true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,196 @@ | ||
| package org.simiancage.DeathTpPlus.listeners; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: PlayerListenerDTP | ||
| * User: DonRedhorse | ||
| * Date: 19.10.11 | ||
| * Time: 22:01 | ||
| */ | ||
|
|
||
| import org.bukkit.Location; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.block.Block; | ||
| import org.bukkit.block.Chest; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.Event.Result; | ||
| import org.bukkit.event.block.Action; | ||
| import org.bukkit.event.player.PlayerInteractEvent; | ||
| import org.bukkit.event.player.PlayerJoinEvent; | ||
| import org.bukkit.event.player.PlayerListener; | ||
| import org.bukkit.event.player.PlayerRespawnEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.TombStoneHelperDTP; | ||
| import org.simiancage.DeathTpPlus.models.TombStoneBlockDTP; | ||
| import org.simiancage.DeathTpPlus.workers.TombWorkerDTP; | ||
|
|
||
| public class PlayerListenerDTP extends PlayerListener { | ||
| private DeathTpPlus plugin; | ||
| private ConfigDTP config; | ||
| private LoggerDTP log; | ||
| private TombWorkerDTP worker; | ||
| private TombStoneHelperDTP tombStoneHelper; | ||
|
|
||
| public PlayerListenerDTP(DeathTpPlus instance) { | ||
| this.plugin = instance; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| worker = TombWorkerDTP.getInstance(); | ||
| tombStoneHelper = TombStoneHelperDTP.getInstance(); | ||
| log.debug("PlayerListener active"); | ||
| } | ||
|
|
||
| @Override | ||
| public void onPlayerInteract(PlayerInteractEvent event) { | ||
| log.debug("onPlayerInteractDTP executing"); | ||
|
|
||
| if (config.isEnableTombStone()) { | ||
| if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { | ||
| return; | ||
| } | ||
| Block b = event.getClickedBlock(); | ||
|
|
||
| if (b.getType() != Material.SIGN_POST && b.getType() != Material.CHEST) { | ||
| return; | ||
| } | ||
| // We'll do quickloot on rightclick of chest if we're going to destroy | ||
| // it anyways | ||
|
|
||
| if (b.getType() == Material.CHEST | ||
| && (!config.isDestroyOnQuickLoot() || config.isAllowTombStoneDestroy())) { | ||
| return; | ||
| } | ||
| if (!plugin.hasPerm(event.getPlayer(), "tombstone.quickloot", false)) { | ||
| return; | ||
| } | ||
|
|
||
| TombStoneBlockDTP tStoneBlockDTP = tombStoneHelper.getTombStoneBlockList(b.getLocation()); | ||
| if (tStoneBlockDTP == null || !(tStoneBlockDTP.getBlock().getState() instanceof Chest)) { | ||
| log.debug("Not a Tombstone!"); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| if (!tStoneBlockDTP.getOwner().equals(event.getPlayer().getName())) { | ||
| log.debug("Owner of tombstone", tStoneBlockDTP.getOwner()); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| Chest sChest = (Chest) tStoneBlockDTP.getBlock().getState(); | ||
| Chest lChest = (tStoneBlockDTP.getLBlock() != null) ? (Chest) tStoneBlockDTP | ||
| .getLBlock().getState() : null; | ||
|
|
||
| ItemStack[] items = sChest.getInventory().getContents(); | ||
| boolean overflow = false; | ||
| for (int cSlot = 0; cSlot < items.length; cSlot++) { | ||
| ItemStack item = items[cSlot]; | ||
| if (item == null) { | ||
| continue; | ||
| } | ||
| if (item.getType() == Material.AIR) { | ||
| continue; | ||
| } | ||
| int slot = event.getPlayer().getInventory().firstEmpty(); | ||
| if (slot == -1) { | ||
| overflow = true; | ||
| break; | ||
| } | ||
| event.getPlayer().getInventory().setItem(slot, item); | ||
| sChest.getInventory().clear(cSlot); | ||
| } | ||
| if (lChest != null) { | ||
| items = lChest.getInventory().getContents(); | ||
| for (int cSlot = 0; cSlot < items.length; cSlot++) { | ||
| ItemStack item = items[cSlot]; | ||
| if (item == null) { | ||
| continue; | ||
| } | ||
| if (item.getType() == Material.AIR) { | ||
| continue; | ||
| } | ||
| int slot = event.getPlayer().getInventory().firstEmpty(); | ||
| if (slot == -1) { | ||
| overflow = true; | ||
| break; | ||
| } | ||
| event.getPlayer().getInventory().setItem(slot, item); | ||
| lChest.getInventory().clear(cSlot); | ||
| } | ||
| } | ||
| Player player = event.getPlayer(); | ||
| int storedDroppedExperience = tStoneBlockDTP.getDroppedExperience(); | ||
| int playerTotalExperience = player.getTotalExperience(); | ||
| log.debug("Player TotalExperience", playerTotalExperience); | ||
| log.debug("Stored droppedExperience", storedDroppedExperience); | ||
| player.setTotalExperience(storedDroppedExperience + playerTotalExperience); | ||
| log.debug("Player New TotalExperience", player.getTotalExperience()); | ||
| if (!overflow) { | ||
| // We're quicklooting, so no need to resume this interaction | ||
| event.setUseInteractedBlock(Result.DENY); | ||
| event.setUseItemInHand(Result.DENY); | ||
| // TODO: Minor bug here - if | ||
| // you're holding a sign, | ||
| // it'll still pop up | ||
| event.setCancelled(true); | ||
|
|
||
| if (config.isDestroyOnQuickLoot()) { | ||
| tombStoneHelper.destroyTombStone(tStoneBlockDTP); | ||
| } | ||
| } | ||
|
|
||
| // Manually update inventory for the time being. | ||
| event.getPlayer().updateInventory(); | ||
| plugin.sendMessage(event.getPlayer(), "Tombstone quicklooted!"); | ||
| Location location = tStoneBlockDTP.getBlock().getLocation(); | ||
| String loc = location.getWorld().getName(); | ||
| loc = loc + ", x=" + location.getBlock().getX(); | ||
| loc = loc + ", y=" + location.getBlock().getY(); | ||
| loc = loc + ", z=" + location.getBlock().getZ(); | ||
| log.debug(event.getPlayer().getName() + " quicklooted tombstone at " | ||
| + loc); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onPlayerJoin(PlayerJoinEvent event) { | ||
| String playerName = event.getPlayer().getName(); | ||
| if (worker.hasTomb(playerName)) { | ||
| worker.getTomb(playerName).checkSigns(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void onPlayerRespawn(PlayerRespawnEvent event) { | ||
| Player p = event.getPlayer(); | ||
|
|
||
| log.debug("hasTomb", worker.hasTomb(p.getName())); | ||
| if (config.isUseTombAsRespawnPoint() && worker.hasTomb(p.getName())) { | ||
| String deathWorld = event.getPlayer().getWorld().getName(); | ||
| Location respawn = worker.getTomb(p.getName()).getRespawn(); | ||
| log.debug("respawn", respawn); | ||
| if (respawn != null) { | ||
| boolean worldTravel = false; | ||
| String spawnWorld = respawn.getWorld().getName(); | ||
| boolean sameWorld = deathWorld.equalsIgnoreCase(spawnWorld); | ||
| if (config.getAllowWorldTravel().equalsIgnoreCase("yes") || (config.getAllowWorldTravel().equalsIgnoreCase("permissions") && p.hasPermission("deathtpplus.worldtravel"))) { | ||
| worldTravel = true; | ||
| } | ||
| log.debug("sameWorld", sameWorld); | ||
| log.debug("worldTravel", worldTravel); | ||
| if (sameWorld || worldTravel) { | ||
| log.debug("Respawn location set to Tomb"); | ||
| event.setRespawnLocation(respawn); | ||
| plugin.sendMessage(p, worker.graveDigger + "You have been resurrected at your Tomb!"); | ||
| } else { | ||
| log.debug("Respawn location not set to Tomb"); | ||
| plugin.sendMessage(p, worker.graveDigger + "You don't have the right to travel between worlds when you die!"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,122 @@ | ||
| package org.simiancage.DeathTpPlus.listeners; | ||
|
|
||
| //import org.bukkit.event.Listener; | ||
|
|
||
| import com.garbagemule.MobArena.MobArenaHandler; | ||
| import com.griefcraft.lwc.LWCPlugin; | ||
| import net.milkbowl.vault.economy.Economy; | ||
| import org.bukkit.event.server.PluginDisableEvent; | ||
| import org.bukkit.event.server.PluginEnableEvent; | ||
| import org.bukkit.event.server.ServerListener; | ||
| import org.bukkit.plugin.Plugin; | ||
| import org.bukkit.plugin.PluginManager; | ||
| import org.bukkit.plugin.RegisteredServiceProvider; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.yi.acru.bukkit.Lockette.Lockette; | ||
|
|
||
| public class ServerListenerDTP extends ServerListener { | ||
| private static DeathTpPlus plugin; | ||
|
|
||
| private LoggerDTP log; | ||
| private ConfigDTP config; | ||
| private boolean missingEconomyWarn = true; | ||
|
|
||
|
|
||
| public ServerListenerDTP(DeathTpPlus plugin) { | ||
| this.plugin = plugin; | ||
| log = LoggerDTP.getLogger(); | ||
| config = ConfigDTP.getInstance(); | ||
| log.debug("ServerListener active"); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void onPluginDisable(PluginDisableEvent event) { | ||
| log.debug("onPluginDisable executing"); | ||
| PluginManager pm = plugin.getServer().getPluginManager(); | ||
| Plugin checkVault = pm.getPlugin("Vault"); | ||
| if ((checkVault == null) && plugin.isUseVault()) { | ||
| RegisteredServiceProvider<Economy> economyProvider = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); | ||
| if (economyProvider == null) { | ||
| plugin.setUseVault(false); | ||
| plugin.setEconomyActive(false); | ||
| log.info("un-hooked from Vault."); | ||
| log.info("as Vault was unloaded / disabled."); | ||
| } | ||
| } | ||
|
|
||
| if (event.getPlugin() == plugin.getLwcPlugin()) { | ||
| log.info("LWC plugin lost."); | ||
| plugin.setLwcPlugin(null); | ||
| } | ||
|
|
||
| if (event.getPlugin() == plugin.getLockettePlugin()) { | ||
| log.info("Lockette plugin lost."); | ||
| plugin.setLockettePlugin(null); | ||
| } | ||
| Plugin checkMobArena = pm.getPlugin("MobArena"); | ||
| if ((checkMobArena == null) && plugin.isMobArenaEnabled()) { | ||
| log.info("Disabled MobArena protection."); | ||
| log.info("as MobArena was unloaded / disabled."); | ||
| plugin.setMaHandler(null); | ||
| plugin.setMobArenaEnabled(false); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void onPluginEnable(PluginEnableEvent event) { | ||
| log.debug("onPluginEnable executing"); | ||
| PluginManager pm = plugin.getServer().getPluginManager(); | ||
| Plugin checkVault = pm.getPlugin("Vault"); | ||
| Plugin checkMobArena = pm.getPlugin("MobArena"); | ||
| if (checkVault != null && !plugin.isUseVault()) { | ||
| plugin.setUseVault(true); | ||
| log.info("Vault detected"); | ||
| log.info("Checking ecnomony providers now!"); | ||
| } | ||
|
|
||
|
|
||
| if ((!plugin.isEconomyActive() && plugin.isUseVault())) { | ||
|
|
||
| RegisteredServiceProvider<Economy> economyProvider = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); | ||
| if (economyProvider != null) { | ||
| plugin.setEconomy(economyProvider.getProvider()); | ||
| plugin.setEconomyActive(true); | ||
| log.info("Economy provider found: " + plugin.getEconomy().getName()); | ||
|
|
||
| } else { | ||
| if (missingEconomyWarn) { | ||
| log.warning("No economy provider found."); | ||
| log.info("Still waiting for economy provider to show up."); | ||
| missingEconomyWarn = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (plugin.getLwcPlugin() == null) { | ||
| if (event.getPlugin().getDescription().getName() | ||
| .equalsIgnoreCase("LWC")) { | ||
| plugin.setLwcPlugin((LWCPlugin) plugin.checkPlugin(event | ||
| .getPlugin())); | ||
| } | ||
| } | ||
|
|
||
| if (plugin.getLockettePlugin() == null) { | ||
| if (event.getPlugin().getDescription().getName() | ||
| .equalsIgnoreCase("Lockette")) { | ||
| plugin.setLockettePlugin((Lockette) plugin.checkPlugin(event | ||
| .getPlugin())); | ||
| } | ||
| } | ||
|
|
||
| if (checkMobArena != null) { | ||
| log.info("Enabling MobArena protection"); | ||
| plugin.setMaHandler(new MobArenaHandler()); | ||
| plugin.setMobArenaEnabled(true); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,34 @@ | ||
| package org.simiancage.DeathTpPlus.listeners; | ||
|
|
||
| import org.bukkit.event.CustomEventListener; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.event.Listener; | ||
| import org.simiancage.DeathTpPlus.events.DeathStreakEventDTP; | ||
| import org.simiancage.DeathTpPlus.events.KillStreakEventDTP; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlugin | ||
| * Class: StreakEventListenerDTP | ||
| * User: DonRedhorse | ||
| * Date: 26.11.11 | ||
| * Time: 19:53 | ||
| */ | ||
|
|
||
| public class StreakEventsListenerDTP extends CustomEventListener implements Listener { | ||
| public StreakEventsListenerDTP() { | ||
| } | ||
|
|
||
| public void onDeathStreakEvent(DeathStreakEventDTP event) { | ||
| } | ||
|
|
||
| public void onKillStreakEvent(KillStreakEventDTP event) { | ||
| } | ||
|
|
||
| public void onCustomEvent(Event event) { | ||
| if (event instanceof DeathStreakEventDTP) { | ||
| onDeathStreakEvent((DeathStreakEventDTP) event); | ||
| } else if (event instanceof KillStreakEventDTP) { | ||
| onKillStreakEvent((KillStreakEventDTP) event); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,51 @@ | ||
| package org.simiancage.DeathTpPlus.listeners; | ||
|
|
||
| import org.bukkit.entity.Player; | ||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.events.DeathStreakEventDTP; | ||
| import org.simiancage.DeathTpPlus.events.KillStreakEventDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
|
|
||
| /** | ||
| * PluginName: ${plugin} | ||
| * Class: StreakListenerDTP | ||
| * User: DonRedhorse | ||
| * Date: 26.11.11 | ||
| * Time: 19:57 | ||
| */ | ||
|
|
||
| public class StreakListenerDTP extends StreakEventsListenerDTP { | ||
| private DeathTpPlus plugin; | ||
| private ConfigDTP config = ConfigDTP.getInstance(); | ||
|
|
||
| public StreakListenerDTP(DeathTpPlus plugin) { | ||
| this.plugin = plugin; | ||
| } | ||
|
|
||
| @Override | ||
| public void onDeathStreakEvent(DeathStreakEventDTP event) { | ||
| String playerName = getPlayerNameForBroadcast(event.getPlayer()); | ||
| plugin.getServer().broadcastMessage(event.getMessage().replace("%n", playerName)); | ||
| } | ||
|
|
||
| @Override | ||
| public void onKillStreakEvent(KillStreakEventDTP event) { | ||
| String playerName = getPlayerNameForBroadcast(event.getPlayer()); | ||
| plugin.getServer().broadcastMessage(event.getMessage().replace("%n", playerName)); | ||
| } | ||
|
|
||
| private String getPlayerNameForBroadcast(Player player) { | ||
| String playerName = player.getName(); | ||
| if (config.isUseDisplayNameforBroadcasts()) { | ||
| playerName = player.getDisplayName(); | ||
| } | ||
| if (playerName.contains("*")) { | ||
| playerName = playerName.replace("*", ""); | ||
| } | ||
| //Todo Add NPE handling for specific errors here, have no idea atm what that could be | ||
| //ToDo we will need input from users about that | ||
|
|
||
| return playerName; | ||
| } | ||
| } | ||
|
|
| @@ -0,0 +1,22 @@ | ||
| package org.simiancage.DeathTpPlus.listeners; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlugin | ||
| * Class: WorldSaveListenerDTP | ||
| * User: DonRedhorse | ||
| * Date: 14.11.11 | ||
| * Time: 20:47 | ||
| */ | ||
|
|
||
| import org.bukkit.event.world.WorldListener; | ||
| import org.bukkit.event.world.WorldSaveEvent; | ||
| import org.simiancage.DeathTpPlus.workers.TombWorkerDTP; | ||
|
|
||
|
|
||
| public class WorldSaveListenerDTP extends WorldListener { | ||
| @Override | ||
| public void onWorldSave(WorldSaveEvent event) { | ||
| TombWorkerDTP.getInstance().save(); | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,108 @@ | ||
| package org.simiancage.DeathTpPlus.logs; | ||
|
|
||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathDetailDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathLocationRecordDTP; | ||
|
|
||
| import java.io.*; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPlus | ||
| * Class: DeathLocationsLogDTP | ||
| * User: DonRedhorse | ||
| * Date: 25.11.11 | ||
| * Time: 19:25 | ||
| */ | ||
|
|
||
| public class DeathLocationsLogDTP { | ||
| private static final String LOCATION_LOG_FILE = "locs.txt"; | ||
| private static final ConfigDTP config = ConfigDTP.getInstance(); | ||
| private static final LoggerDTP log = LoggerDTP.getLogger(); | ||
| private DeathTpPlus plugin; | ||
| private String dataFolder; | ||
| private File deathLocationLogFile; | ||
|
|
||
| public DeathLocationsLogDTP(DeathTpPlus plugin) { | ||
| this.plugin = plugin; | ||
| dataFolder = plugin.getDataFolder() + System.getProperty("file.separator"); | ||
| deathLocationLogFile = new File(dataFolder, LOCATION_LOG_FILE); | ||
| if (!deathLocationLogFile.exists()) { | ||
| try { | ||
| deathLocationLogFile.createNewFile(); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to create death location log", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public DeathLocationRecordDTP getRecord(String playerName) { | ||
| DeathLocationRecordDTP deathLocation = null; | ||
|
|
||
| try { | ||
| BufferedReader bufferedReader = new BufferedReader(new FileReader(deathLocationLogFile)); | ||
| String line = null; | ||
|
|
||
| while ((line = bufferedReader.readLine()) != null) { | ||
| deathLocation = new DeathLocationRecordDTP(line); | ||
| if (playerName.equalsIgnoreCase(deathLocation.getPlayerName())) { | ||
| return deathLocation; | ||
| } else { | ||
| deathLocation = null; | ||
| } | ||
| } | ||
|
|
||
| bufferedReader.close(); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to read death location log", e); | ||
| } | ||
|
|
||
| return deathLocation; | ||
| } | ||
|
|
||
| public void setRecord(DeathDetailDTP deathDetail) { | ||
| List<DeathLocationRecordDTP> deathLocations = new ArrayList<DeathLocationRecordDTP>(); | ||
| DeathLocationRecordDTP playerRecord = null; | ||
|
|
||
| try { | ||
| BufferedReader deathLocationLogReader = new BufferedReader(new FileReader(deathLocationLogFile)); | ||
|
|
||
| String line = null; | ||
| while ((line = deathLocationLogReader.readLine()) != null) { | ||
| DeathLocationRecordDTP deathLocation = new DeathLocationRecordDTP(line); | ||
| if (deathDetail.getPlayer().getName().equalsIgnoreCase(deathLocation.getPlayerName())) { | ||
| deathLocation.setLocation(deathDetail.getPlayer().getLocation()); | ||
| deathLocation.setWorldName(deathDetail.getPlayer().getWorld().getName()); | ||
| playerRecord = deathLocation; | ||
| } | ||
| deathLocations.add(deathLocation); | ||
| } | ||
|
|
||
| deathLocationLogReader.close(); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to read death location log", e); | ||
| } | ||
|
|
||
| if (playerRecord == null) { | ||
| playerRecord = new DeathLocationRecordDTP(deathDetail.getPlayer()); | ||
| deathLocations.add(playerRecord); | ||
| } | ||
|
|
||
| try { | ||
| BufferedWriter deathLocationLogWriter = new BufferedWriter(new FileWriter(deathLocationLogFile)); | ||
|
|
||
| for (DeathLocationRecordDTP deathLocation : deathLocations) { | ||
| deathLocationLogWriter.write(deathLocation.toString()); | ||
| deathLocationLogWriter.newLine(); | ||
| log.debug("DeathLocation written:", deathLocation); | ||
| } | ||
|
|
||
| deathLocationLogWriter.close(); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to write death location log", e); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,144 @@ | ||
| package org.simiancage.DeathTpPlus.logs; | ||
|
|
||
| import org.simiancage.DeathTpPlus.DeathTpPlus; | ||
| import org.simiancage.DeathTpPlus.helpers.ConfigDTP; | ||
| import org.simiancage.DeathTpPlus.helpers.LoggerDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathDetailDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathRecordDTP; | ||
| import org.simiancage.DeathTpPlus.models.DeathRecordDTP.DeathRecordType; | ||
|
|
||
| import java.io.*; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * PluginName: DeathTpPLus | ||
| * Class: DeathLogDTP | ||
| * User: DonRedhorse | ||
| * Date: 25.11.11 | ||
| * Time: 19:19 | ||
| */ | ||
|
|
||
| public class DeathLogDTP { | ||
| private static final String DEATH_LOG_FILE = "deathlog.txt"; | ||
| private static final String DEATH_LOG_TMP = "deathlog.tmp"; | ||
| private static final ConfigDTP config = ConfigDTP.getInstance(); | ||
| private static final LoggerDTP log = LoggerDTP.getLogger(); | ||
| private String dataFolder; | ||
| private File deathLogFile; | ||
| private DeathTpPlus plugin; | ||
|
|
||
| public DeathLogDTP(DeathTpPlus plugin) { | ||
| this.plugin = plugin; | ||
| dataFolder = plugin.getDataFolder() + System.getProperty("file.separator"); | ||
| deathLogFile = new File(dataFolder, DEATH_LOG_FILE); | ||
| if (!deathLogFile.exists()) { | ||
| try { | ||
| deathLogFile.createNewFile(); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to create death log", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public int getTotalByType(String playerName, DeathRecordType type) { | ||
| List<DeathRecordDTP> records = getRecords(playerName); | ||
| int totalDeaths = -1; | ||
|
|
||
| for (DeathRecordDTP record : records) { | ||
| if (record.getPlayerName().equalsIgnoreCase(playerName) && record.getType() == type) { | ||
| totalDeaths += record.getCount(); | ||
| } | ||
| } | ||
|
|
||
| return totalDeaths; | ||
| } | ||
|
|
||
| public DeathRecordDTP getRecordByType(String playerName, String eventName, DeathRecordType type) { | ||
| List<DeathRecordDTP> records = getRecords(playerName); | ||
|
|
||
| for (DeathRecordDTP record : records) { | ||
| if (record.getPlayerName().equalsIgnoreCase(playerName) && record.getType() == type && record.getEventName().equalsIgnoreCase(eventName)) { | ||
| return record; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| List<DeathRecordDTP> getRecords(String playerName) { | ||
| List<DeathRecordDTP> records = new ArrayList<DeathRecordDTP>(); | ||
|
|
||
| try { | ||
| BufferedReader bufferedReader = new BufferedReader(new FileReader(deathLogFile)); | ||
| String line = null; | ||
| while ((line = bufferedReader.readLine()) != null) { | ||
| DeathRecordDTP deathRecord = new DeathRecordDTP(line); | ||
| if (playerName.equalsIgnoreCase(deathRecord.getPlayerName())) { | ||
| records.add(deathRecord); | ||
| } | ||
| } | ||
|
|
||
| bufferedReader.close(); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to read death log", e); | ||
| } | ||
|
|
||
| return records; | ||
| } | ||
|
|
||
| public void setRecord(DeathDetailDTP deathDetail) { | ||
| if (deathDetail.isPVPDeath()) { | ||
| setRecord(deathDetail.getKiller().getName(), DeathRecordType.kill, deathDetail.getPlayer().getName()); | ||
| setRecord(deathDetail.getPlayer().getName(), DeathRecordType.death, deathDetail.getKiller().getName()); | ||
| } else { | ||
| setRecord(deathDetail.getPlayer().getName(), DeathRecordType.death, deathDetail.getCauseOfDeath().toString()); | ||
| } | ||
| } | ||
|
|
||
| @Deprecated | ||
| void setRecord(String playerName, DeathRecordType type, String eventName) { | ||
| File tmpDeathLogFile = new File(dataFolder, DEATH_LOG_TMP); | ||
| DeathRecordDTP playerRecord = null; | ||
|
|
||
| if (!tmpDeathLogFile.exists()) { | ||
| try { | ||
| tmpDeathLogFile.createNewFile(); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to create tmp death log", e); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| BufferedWriter tmpDeathLogWriter = new BufferedWriter(new FileWriter(tmpDeathLogFile)); | ||
| BufferedReader deathLogReader = new BufferedReader(new FileReader(deathLogFile)); | ||
|
|
||
| String line = null; | ||
| while ((line = deathLogReader.readLine()) != null) { | ||
| DeathRecordDTP deathRecord = new DeathRecordDTP(line); | ||
| if (playerName.equalsIgnoreCase(deathRecord.getPlayerName()) && type == deathRecord.getType() && eventName.equalsIgnoreCase(deathRecord.getEventName())) { | ||
| deathRecord.setCount(deathRecord.getCount() + 1); | ||
| playerRecord = deathRecord; | ||
| } | ||
|
|
||
| tmpDeathLogWriter.write(deathRecord.toString()); | ||
| tmpDeathLogWriter.newLine(); | ||
| } | ||
|
|
||
| if (playerRecord == null) { | ||
| playerRecord = new DeathRecordDTP(playerName, type, eventName, 1); | ||
| tmpDeathLogWriter.write(playerRecord.toString()); | ||
| tmpDeathLogWriter.newLine(); | ||
| } | ||
|
|
||
| tmpDeathLogWriter.close(); | ||
| deathLogReader.close(); | ||
|
|
||
| deathLogFile.delete(); | ||
| tmpDeathLogFile.renameTo(deathLogFile); | ||
| } catch (IOException e) { | ||
| log.severe("Failed to edit death log", e); | ||
| } | ||
| } | ||
| } | ||
|
|