From e30e60da28bb62c42df2bf24d8880e24e5f9e0dd Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 30 Aug 2016 18:17:37 +0200 Subject: [PATCH 1/5] Fix crash at plugin load --- src/iie/HelloWorldPlugin.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/iie/HelloWorldPlugin.java b/src/iie/HelloWorldPlugin.java index 382729e..4061f63 100644 --- a/src/iie/HelloWorldPlugin.java +++ b/src/iie/HelloWorldPlugin.java @@ -8,20 +8,21 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; - public class HelloWorldPlugin extends JavaPlugin { - + public static Scoreboard board; - public static Objective hardcoreTimeDead; - public static AbstractMap deathMap = new HashMap(); - - public void onEnable(){ + public static Objective hardcoreTimeDead; + public static AbstractMap deathMap = new HashMap(); + + public void onEnable() { registerCommands(); getServer().getPluginManager().registerEvents(new DeathListener(this), this); board = Bukkit.getServer().getScoreboardManager().getMainScoreboard(); - hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); + if (board.getObjective("hardcoreTimeDead") == null) + hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy"); } - public void registerCommands(){ + + public void registerCommands() { getCommand("HelloWorld").setExecutor(new HelloWorld(this)); } From 1a66291958d2210f4db0830ecee056abd6e11df4 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 31 Aug 2016 02:36:49 -0400 Subject: [PATCH 2/5] Started work on ConflictRTP --- src/alisolarflare/RandomTP.java | 113 +++++++++++++++++++++++++++++--- 1 file changed, 105 insertions(+), 8 deletions(-) diff --git a/src/alisolarflare/RandomTP.java b/src/alisolarflare/RandomTP.java index a2378d4..b2e4fcb 100644 --- a/src/alisolarflare/RandomTP.java +++ b/src/alisolarflare/RandomTP.java @@ -7,32 +7,129 @@ import org.bukkit.entity.Player; public class RandomTP{ - //Randomly teleports a player, into the hardcore world - public void rtp(Player player, World world, Location minLocation, Location maxLocation){ - - + + private int conflictX; + private int conflictZ; + private int conflictCycle; + private int conflictRadius = 70; + private boolean northUsed; + private boolean southUsed; + private boolean eastUsed; + private boolean westUsed; + //every 4 players who use it will be teleported near each other. + //ex. iie > 1200, ali -> 1210, byz -> 1190, charles -> 1195, wind -> 300, zan -> 310, etc + public void conflictRtp(Player player, World world, Location minLocation, Location maxLocation){ //INIT - xDifference, xAverage int xdifference = minLocation.getBlockX() - maxLocation.getBlockX(); int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2); - + //INIT - zDifference, zAverage int zdifference = minLocation.getBlockX() - maxLocation.getBlockY(); int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ()); + //CHECK - Reset Cycle + if ((northUsed || southUsed || eastUsed || westUsed) == false){ + + //Tries 20 times to find a location + for(int i = 0; i < 20; i ++){ + + //INIT - attemptedX, attemptedZ + int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage; + int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage; + + int cr = conflictRadius; + + + //CHECKS - if ground is safe + boolean groundIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER; + boolean northIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ-cr).getType() != Material.WATER; + boolean eastIsSafe = world.getHighestBlockAt(attemptedX+cr, attemptedZ).getType() != Material.WATER; + boolean southIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ+cr).getType() != Material.WATER; + boolean westIsSafe = world.getHighestBlockAt(attemptedX-cr, attemptedZ).getType() != Material.WATER; + + //TRANSFER - data to class + if (groundIsSafe && (northIsSafe || southIsSafe || eastIsSafe || westIsSafe)){ + + northUsed = northIsSafe; + eastUsed = eastIsSafe; + westUsed = westIsSafe; + southUsed = southIsSafe; + conflictX = attemptedX; + conflictZ = attemptedZ; + + player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation()); + break; + } + } + } + + int dir = 0; + //CHOOSES A RANDOM DIRECTION + for(int i = 0; i < 1000; i++){ + double randomDirection = Math.random(); + if (randomDirection < 0.25){ + if(northUsed){ + northUsed = true; + dir = 0; + break; + } + }else if(randomDirection < 0.50){ + if(eastUsed){ + eastUsed = true; + dir = 1; + break; + } + }else if(randomDirection < 0.75){ + if(southUsed){ + southUsed = true; + dir = 2; + break; + } + }else{ + if(westUsed){ + westUsed = true; + dir = 3; + break; + } + + } + } + + + + + + //INCREMENT - shift cycle + conflictCycle++; + //conflict cycle - 0:N, 1:E, 2:S, 3:W + } + + //Randomly teleports a player, into the hardcore world + public void rtp(Player player, World world, Location minLocation, Location maxLocation){ + + + //INIT - xDifference, xAverage + int xdifference = minLocation.getBlockX() - maxLocation.getBlockX(); + int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2); + + //INIT - zDifference, zAverage + int zdifference = minLocation.getBlockX() - maxLocation.getBlockY(); + int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ()); + //TELEPORTS - Tries 20 times to find a location for(int i = 0; i < 20; i ++){ - + //INIT - attemptedX, attemptedZ int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage; int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage; - + //CHECKS - if ground is safe boolean groundisSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER; if (groundisSafe){ player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation()); return; } - + //player.teleport(arg0) } } From 2b4ba7f8ebdec8e3fdfdf37b204ecce1dc1e7ff3 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 31 Aug 2016 08:05:56 -0400 Subject: [PATCH 3/5] Finished ConflictRTP code --- src/alisolarflare/RandomTP.java | 39 +++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/alisolarflare/RandomTP.java b/src/alisolarflare/RandomTP.java index b2e4fcb..f9c1016 100644 --- a/src/alisolarflare/RandomTP.java +++ b/src/alisolarflare/RandomTP.java @@ -10,7 +10,6 @@ public class RandomTP{ private int conflictX; private int conflictZ; - private int conflictCycle; private int conflictRadius = 70; private boolean northUsed; private boolean southUsed; @@ -63,32 +62,32 @@ public class RandomTP{ } } - int dir = 0; + String dir = "north"; //CHOOSES A RANDOM DIRECTION for(int i = 0; i < 1000; i++){ double randomDirection = Math.random(); if (randomDirection < 0.25){ if(northUsed){ northUsed = true; - dir = 0; + dir = "north"; break; } }else if(randomDirection < 0.50){ if(eastUsed){ eastUsed = true; - dir = 1; + dir = "east"; break; } }else if(randomDirection < 0.75){ if(southUsed){ southUsed = true; - dir = 2; + dir = "south"; break; } }else{ if(westUsed){ westUsed = true; - dir = 3; + dir = "west"; break; } @@ -96,12 +95,28 @@ public class RandomTP{ } - - - - //INCREMENT - shift cycle - conflictCycle++; - //conflict cycle - 0:N, 1:E, 2:S, 3:W + //TELEPORT - teleports player to the conflict point + switch(dir){ + case "north": + northUsed = false; + player.teleport(world.getHighestBlockAt(conflictX, conflictZ - conflictRadius).getLocation()); + break; + case "east": + eastUsed = false; + player.teleport(world.getHighestBlockAt(conflictX + conflictRadius, conflictZ).getLocation()); + break; + case "south": + southUsed = false; + player.teleport(world.getHighestBlockAt(conflictX, conflictZ + conflictRadius).getLocation()); + break; + case "west": + westUsed = false; + player.teleport(world.getHighestBlockAt(conflictX - conflictRadius, conflictZ).getLocation()); + break; + default: + player.teleport(world.getHighestBlockAt(conflictX, conflictZ).getLocation()); + break; + } } //Randomly teleports a player, into the hardcore world From 6932fa56dd74a240c850c044e46c35fcb1f71aba Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 31 Aug 2016 08:10:15 -0400 Subject: [PATCH 4/5] Changed Listeners to return boolean values --- .../listeners/ConflictCompassCraftingListener.java | 14 ++++++++++++++ .../listeners/DiamondArmorBlocker.java | 5 +++-- src/iie/DeathListener.java | 7 ++++--- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 src/alisolarflare/listeners/ConflictCompassCraftingListener.java diff --git a/src/alisolarflare/listeners/ConflictCompassCraftingListener.java b/src/alisolarflare/listeners/ConflictCompassCraftingListener.java new file mode 100644 index 0000000..e7f1f58 --- /dev/null +++ b/src/alisolarflare/listeners/ConflictCompassCraftingListener.java @@ -0,0 +1,14 @@ +package alisolarflare.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.CraftItemEvent; + +public class ConflictCompassCraftingListener implements Listener{ + + @EventHandler + public boolean onConflictCompassCraft(CraftItemEvent event){ + + return false; + } +} diff --git a/src/alisolarflare/listeners/DiamondArmorBlocker.java b/src/alisolarflare/listeners/DiamondArmorBlocker.java index 52c7547..842f307 100644 --- a/src/alisolarflare/listeners/DiamondArmorBlocker.java +++ b/src/alisolarflare/listeners/DiamondArmorBlocker.java @@ -15,10 +15,10 @@ import org.bukkit.inventory.ItemStack; public class DiamondArmorBlocker implements Listener{ public static List blockedItems = Arrays.asList(Material.DIAMOND_BOOTS, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_HELMET); @EventHandler - public void onArmorSmith(CraftItemEvent event){ + public boolean onArmorSmith(CraftItemEvent event){ //SANITATION - hardcore if(event.getWhoClicked().getWorld().getName() != "hardcore"){ - return; + return false; } //INIT - inventory, targetItem @@ -33,6 +33,7 @@ public class DiamondArmorBlocker implements Listener{ event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0); event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.ENTITY_ITEM_BREAK,0,0); } + return false; } diff --git a/src/iie/DeathListener.java b/src/iie/DeathListener.java index 36aa3c1..964aef3 100644 --- a/src/iie/DeathListener.java +++ b/src/iie/DeathListener.java @@ -19,7 +19,7 @@ public class DeathListener implements Listener { } @EventHandler(priority = EventPriority.MONITOR) - public void onHardcoreDeath(PlayerDeathEvent deathEvent){ + public boolean onHardcoreDeath(PlayerDeathEvent deathEvent){ String timeString = String.valueOf(System.currentTimeMillis()); Player player = deathEvent.getEntity(); @@ -40,11 +40,12 @@ public class DeathListener implements Listener { //player.sendMessage("Key saved: " + playerString); //player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString)); } + return false; } @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerLogin(PlayerJoinEvent joinEvent){ + public boolean onPlayerLogin(PlayerJoinEvent joinEvent){ @@ -65,7 +66,7 @@ public class DeathListener implements Listener { if (HelloWorldPlugin.deathMap.get(playerString) == null && score.getScore() != 0){ HelloWorldPlugin.deathMap.put(playerString, String.valueOf((score.getScore()) * 1000)); } - + return false; } } From f9b4d9abe4dd1ad971fc40a8489cc67c98f1c32d Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 31 Aug 2016 08:33:45 -0400 Subject: [PATCH 5/5] Created a Conflict Compass Crafting listener --- .../ConflictCompassCraftingListener.java | 56 ++++++++++++++++++- .../listeners/DiamondArmorBlocker.java | 3 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/alisolarflare/listeners/ConflictCompassCraftingListener.java b/src/alisolarflare/listeners/ConflictCompassCraftingListener.java index e7f1f58..ee2c355 100644 --- a/src/alisolarflare/listeners/ConflictCompassCraftingListener.java +++ b/src/alisolarflare/listeners/ConflictCompassCraftingListener.java @@ -1,14 +1,68 @@ package alisolarflare.listeners; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.inventory.ItemStack; public class ConflictCompassCraftingListener implements Listener{ - + @EventHandler public boolean onConflictCompassCraft(CraftItemEvent event){ + //SANITATION - HARDCORE + if(event.getWhoClicked().getWorld().getName() != "hardcore"){ + return false; + } + //INIT - targetItem + ItemStack targetItem = event.getRecipe().getResult(); + + //SANITATION - NOT COMPASS + if(targetItem.getType() != Material.COMPASS){ + return false; + } + + event.setCancelled(true); + //GIVE - chainmail chestplate + event.getWhoClicked().getInventory().addItem(generateConflictCompass(event.getWhoClicked())); + //PLAY - cave sound + event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0); return false; } + + private ItemStack generateConflictCompass(HumanEntity crafter) { + ItemStack conflictCompass = new ItemStack(Material.COMPASS); + conflictCompass.addUnsafeEnchantment(Enchantment.DURABILITY, 1); + List loreString = new ArrayList(); + loreString.add("The needle is tipped with the scent of"); + + loreString.add(nearestPlayerName(crafter)); + conflictCompass.getItemMeta().setLore(loreString); + return null; + } + + private String nearestPlayerName(HumanEntity crafter) { + Player nearestPlayer = null; + for(Player player: crafter.getWorld().getPlayers()){ + if (player.getUniqueId() == crafter.getUniqueId()){ + //SKIP CODE + }if (nearestPlayer == null){ + nearestPlayer = player; + }else if (nearestPlayer.getLocation().distance(crafter.getLocation()) > player.getLocation().distance(crafter.getLocation())){ + nearestPlayer = player; + } + } + if(nearestPlayer == null){ + return "METAL"; + } + return nearestPlayer.toString(); + } } diff --git a/src/alisolarflare/listeners/DiamondArmorBlocker.java b/src/alisolarflare/listeners/DiamondArmorBlocker.java index 842f307..277dd36 100644 --- a/src/alisolarflare/listeners/DiamondArmorBlocker.java +++ b/src/alisolarflare/listeners/DiamondArmorBlocker.java @@ -43,7 +43,8 @@ public class DiamondArmorBlocker implements Listener{ //INIT - Chainmail's lore List loreString = new ArrayList(); - loreString.add("This world is forever dangerous. There is no protection here"); + loreString.add("This world is forever dangerous."); + loreString.add("There is no protection here."); failArmor.getItemMeta().setLore(loreString); return failArmor; }