From d2d4e822225e536f15a438e5cd407c69ea1857c1 Mon Sep 17 00:00:00 2001 From: Henry5041 Date: Sat, 9 Jul 2016 21:00:42 +0800 Subject: [PATCH] Recovered lost codes by decompilation to version 0.2.0 --- .classpath | 31 ++ .gitignore | 1 + .project | 23 ++ .settings/org.eclipse.jdt.core.prefs | 5 + .settings/org.eclipse.m2e.core.prefs | 4 + dependency-reduced-pom.xml | 94 ++++++ pom.xml | 112 ++++--- .../greensky/platformjump/Configuration.java | 45 +++ .../org/greensky/platformjump/Platform.java | 190 ++++++------ .../greensky/platformjump/PlatformJump.java | 149 ++++++---- .../PlatformJumpCommandExecutor.java | 147 ++++++--- .../platformjump/PlatformJumpListener.java | 279 ++++++++++-------- src/main/resources/config.yml | 34 ++- src/main/resources/plugin.yml | 101 ++++--- .../platformjump/PlatformJumpTest.java | 2 +- 15 files changed, 798 insertions(+), 419 deletions(-) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 dependency-reduced-pom.xml create mode 100644 src/main/java/org/greensky/platformjump/Configuration.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..8ea88f8 --- /dev/null +++ b/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.project b/.project new file mode 100644 index 0000000..6fa082c --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + PlatformJump + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d59e09c --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..14b697b --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..ef776fe --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + org.greensky + PlatformJump + 0.2.1-SNAPSHOT + + + + maven-compiler-plugin + + 1.8 + 1.8 + + + + maven-shade-plugin + 2.3 + + + package + + shade + + + + + + + org.mcstats.*:* + + + + + org.mcstats + org.greensky.platformjump + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + Plugin Metrics + http://repo.mcstats.org/content/repositories/public + + + + + org.bukkit + bukkit + 1.10.2-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + + + json-simple + com.googlecode.json-simple + + + guava + com.google.guava + + + gson + com.google.code.gson + + + ebean + org.avaje + + + snakeyaml + org.yaml + + + + + junit + junit + 4.11 + compile + + + + diff --git a/pom.xml b/pom.xml index 385e478..e24ef72 100644 --- a/pom.xml +++ b/pom.xml @@ -1,38 +1,76 @@ - - 4.0.0 - org.greensky - PlatformJump - 0.0.6-SNAPSHOT - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.7 - 1.7 - - - - - - - bukkit-repo - http://repo.bukkit.org/content/groups/public/ - - - - - org.bukkit - bukkit - 1.7.2-R0.3 - jar - provided - - - junit - junit - 4.11 - - + + 4.0.0 + org.greensky + PlatformJump + 0.2.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + + org.mcstats.*:* + + + + + org.mcstats + + org.greensky.platformjump + + + + + + package + + shade + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + Plugin Metrics + http://repo.mcstats.org/content/repositories/public + + + + + + org.bukkit + bukkit + 1.10.2-R0.1-SNAPSHOT + provided + + + org.mcstats.bukkit + metrics + R7 + compile + + + junit + junit + 4.11 + + diff --git a/src/main/java/org/greensky/platformjump/Configuration.java b/src/main/java/org/greensky/platformjump/Configuration.java new file mode 100644 index 0000000..f5113d4 --- /dev/null +++ b/src/main/java/org/greensky/platformjump/Configuration.java @@ -0,0 +1,45 @@ +package org.greensky.platformjump; + +import org.bukkit.configuration.file.FileConfiguration; + +public class Configuration { + private org.bukkit.Material platformMaterial; + private boolean isDebugOn; + private FileConfiguration config; + + @SuppressWarnings("deprecation") + public Configuration(FileConfiguration config) { + this.config = config; + + this.isDebugOn = config.getBoolean("debug"); + this.platformMaterial = org.bukkit.Material.getMaterial(config.getInt("platform.block-id")); + } + + @SuppressWarnings("deprecation") + public void reload() { + this.isDebugOn = this.config.getBoolean("debug"); + this.platformMaterial = org.bukkit.Material.getMaterial(this.config.getInt("platform.block-id")); + } + + public org.bukkit.Material getPlatformMaterial() { + return this.platformMaterial; + } + + public void setPlatformMaterial(org.bukkit.Material platformMaterial) { + this.platformMaterial = platformMaterial; + } + + public boolean isDebugOn() { + return this.isDebugOn; + } + + public void setDebugOn(boolean isDebugOn) { + this.isDebugOn = isDebugOn; + } +} + +/* + * Location: C:\Users\Henry + * Hu\Documents\plugins\PlatformJump-0.2.0.jar!\org\greensky\platformjump\ + * Configuration.class Java compiler version: 7 (51.0) JD-Core Version: 0.7.1 + */ \ No newline at end of file diff --git a/src/main/java/org/greensky/platformjump/Platform.java b/src/main/java/org/greensky/platformjump/Platform.java index 161c666..c3f1422 100644 --- a/src/main/java/org/greensky/platformjump/Platform.java +++ b/src/main/java/org/greensky/platformjump/Platform.java @@ -1,96 +1,94 @@ -package org.greensky.platformjump; - -import java.util.Map; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -public class Platform { - private Map lastPlatformMap; - private boolean isDebugOn; - private Player player; - private int platformType; - - public Platform(Player player) { - this.player = player; - setDebugOn(false); - } - - public boolean createPlatform() { - String playerName = player.getName(); - if (!(lastPlatformMap == null)) { - if (lastPlatformMap.containsKey(playerName)) { - // Sets location for last platform. - Block lastPlatform = lastPlatformMap.get(playerName); - if (lastPlatform.getType() == Material.GLASS) { - // Removes the platform. - lastPlatform.setType(Material.AIR); - lastPlatformMap.remove(playerName); - if (isDebugOn) { - player.sendMessage("Last platform removed"); - } - } - - } - } - - // Get the player's location. - Location playerLocation = player.getLocation(); - // Sets location to one under where it used to be. Note - // that - // doesn't change the player's position. - Location platformLocation = playerLocation.clone(); - platformLocation.setY(platformLocation.getY() - 1); - // Gets the block at the new location. - Block platform = platformLocation.getBlock(); - - if (platform.getType() == Material.AIR) { - // Sets the block to glass. - platform.setType(Material.GLASS); - if (!(lastPlatformMap == null)) { - lastPlatformMap.put(playerName, platform); - - } - if (isDebugOn) { - player.sendMessage("Platform created"); - } - platformLocation.setY((int) (platformLocation.getY())); - // Teleport the player upon the platform - player.teleport(playerLocation); - if (isDebugOn) { - player.sendMessage("Teleported upon the platform"); - } - // Return true if platform created - return true; - } - // Return false if platform isn't created - return false; - } - - public Map getLastPlatformMap() { - return lastPlatformMap; - } - - public void setLastPlatformMap(Map lastPlatformMap) { - this.lastPlatformMap = lastPlatformMap; - } - - public boolean isDebugOn() { - return isDebugOn; - } - - public void setDebugOn(boolean isDebugOn) { - this.isDebugOn = isDebugOn; - } - - public int getPlatformType() { - return platformType; - } - - public void setPlatformType(int platformType) { - this.platformType = platformType; - } - -} +package org.greensky.platformjump; + +import java.util.Map; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +public class Platform { + private Map lastPlatformMap; + private boolean isDebugOn; + private Player player; + private org.bukkit.Material platformMaterial; + + public Platform(Player player) { + this.player = player; + this.lastPlatformMap = null; + setDebugOn(false); + this.platformMaterial = org.bukkit.Material.GLASS; + } + + public boolean createPlatform() { + String playerName = this.player.getName(); + if ((this.lastPlatformMap != null) && (this.lastPlatformMap.containsKey(playerName))) { + Block lastPlatform = (Block) this.lastPlatformMap.get(playerName); + if (lastPlatform.getType() == this.platformMaterial) { + lastPlatform.setType(org.bukkit.Material.AIR); + // Remove the last platform block + this.lastPlatformMap.remove(playerName); + if (this.isDebugOn) { + this.player.sendMessage("Last platform removed"); + } + } + } + + Location playerLocation = this.player.getLocation(); + // Sets location to one under where it used to be, without changing the + // player's own position + Location platformLocation = playerLocation.clone(); + platformLocation.setY(platformLocation.getY() - 1.0D); + + Block platform = platformLocation.getBlock(); + + if (platform.getType() == org.bukkit.Material.AIR) { + platform.setType(this.platformMaterial); + if (this.lastPlatformMap != null) { + this.lastPlatformMap.put(playerName, platform); + } + + if (this.isDebugOn) { + this.player.sendMessage("Platform created"); + } + platformLocation.setY((int) platformLocation.getY()); + // unstuck the player + this.player.teleport(playerLocation); + if (this.isDebugOn) { + this.player.sendMessage("Teleported upon the platform"); + } + + return true; + } + + return false; + } + + public Map getLastPlatformMap() { + return this.lastPlatformMap; + } + + public void setLastPlatformMap(Map lastPlatformMap) { + this.lastPlatformMap = lastPlatformMap; + } + + public boolean isDebugOn() { + return this.isDebugOn; + } + + public void setDebugOn(boolean isDebugOn) { + this.isDebugOn = isDebugOn; + } + + public org.bukkit.Material getPlatformMaterial() { + return this.platformMaterial; + } + + public void setPlatformMaterial(org.bukkit.Material platformType) { + this.platformMaterial = platformType; + } +} + +/* + * Location: C:\Users\Henry + * Hu\Documents\plugins\PlatformJump-0.2.0.jar!\org\greensky\platformjump\ + * Platform.class Java compiler version: 7 (51.0) JD-Core Version: 0.7.1 + */ \ No newline at end of file diff --git a/src/main/java/org/greensky/platformjump/PlatformJump.java b/src/main/java/org/greensky/platformjump/PlatformJump.java index 02c892f..a834744 100644 --- a/src/main/java/org/greensky/platformjump/PlatformJump.java +++ b/src/main/java/org/greensky/platformjump/PlatformJump.java @@ -1,61 +1,88 @@ -package org.greensky.platformjump; - -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class PlatformJump extends JavaPlugin { - public Map pluginEnabled = new HashMap<>(); - private Map lastPlatformMap = new HashMap(); - - @Override - public void onEnable() { - this.saveDefaultConfig(); - this.getCommand("platform").setExecutor(new PlatformJumpCommandExecutor(this)); - getServer().getPluginManager().registerEvents(new PlatformJumpListener(this), this); - } - @Override - public void onDisable(){ - for (Player eachPlayer : Bukkit.getServer() - .getOnlinePlayers()) { - lastPlatformMap.get(eachPlayer.getName()).setType(Material.AIR); - } - } - public boolean getPluginEnabled(String playerName){ - if (!pluginEnabled.containsKey(playerName)){ - pluginEnabled.put(playerName, true); - } - return pluginEnabled.get(playerName); - - } - public void togglePluginState(Player player) { - // Notice how we use the player name as the key here, - // not the player object - String playerName = player.getName(); - if (pluginEnabled.containsKey(playerName)) { - if (pluginEnabled.get(playerName)) { - pluginEnabled.put(playerName, false); - player.sendMessage("Plugin disabled"); - } else { - pluginEnabled.put(playerName, true); - player.sendMessage("Plugin enabled"); - } - } else { - pluginEnabled.put(playerName, true); //If you want plugin disabled by default change this value to false. - player.sendMessage("Plugin enabled"); - } - } - public Map getLastPlatformMap() { - return lastPlatformMap; - } - public void setLastPlatformMap(Map lastPlatformMap) { - this.lastPlatformMap = lastPlatformMap; - } - - -} +package org.greensky.platformjump; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.mcstats.Metrics; + +public class PlatformJump extends org.bukkit.plugin.java.JavaPlugin { + public Map pluginEnabled = new HashMap(); + private Map lastPlatformMap = new HashMap(); + private Configuration configuration; + + public void onEnable() { + saveDefaultConfig(); + this.configuration = new Configuration(getConfig()); + getLogger().info("Debug: " + this.configuration.isDebugOn()); + getLogger().info("Platform Material: " + this.configuration.getPlatformMaterial()); + getCommand("platform").setExecutor(new PlatformJumpCommandExecutor(this)); + getServer().getPluginManager().registerEvents(new PlatformJumpListener(this), this); + if (getConfig().getBoolean("metrics")) { + try { + Metrics metrics = new Metrics(this); + metrics.start(); + } catch (IOException e) { + getLogger().info("enable metrics failed"); + } + } + } + + public void onDisable() { + + for (Player eachPlayer : org.bukkit.Bukkit.getServer().getOnlinePlayers()) { + if (this.lastPlatformMap.containsKey(eachPlayer.getName())) { + ((Block) this.lastPlatformMap.get(eachPlayer.getName())).setType(Material.AIR); + } + } + } + + public boolean getPluginEnabled(String playerName) { + if (!this.pluginEnabled.containsKey(playerName)) { + this.pluginEnabled.put(playerName, Boolean.valueOf(true)); + } + return ((Boolean) this.pluginEnabled.get(playerName)).booleanValue(); + } + + public void togglePluginState(Player player) { + String playerName = player.getName(); + if (this.pluginEnabled.containsKey(playerName)) { + if (((Boolean) this.pluginEnabled.get(playerName)).booleanValue()) { + this.pluginEnabled.put(playerName, Boolean.valueOf(false)); + player.sendMessage(getConfig().getString("message.toggle-off")); + } else { + this.pluginEnabled.put(playerName, Boolean.valueOf(true)); + player.sendMessage(getConfig().getString("message.toggle-on")); + } + } else { + this.pluginEnabled.put(playerName, Boolean.valueOf(true)); + + player.sendMessage(getConfig().getString("message.toggle-on")); + } + } + + public Map getLastPlatformMap() { + return this.lastPlatformMap; + } + + public void setLastPlatformMap(Map lastPlatformMap) { + this.lastPlatformMap = lastPlatformMap; + } + + public Configuration getConfiguration() { + return this.configuration; + } + + public void setConfiguration(Configuration configuration) { + this.configuration = configuration; + } +} + +/* + * Location: C:\Users\Henry + * Hu\Documents\plugins\PlatformJump-0.2.0.jar!\org\greensky\platformjump\ + * PlatformJump.class Java compiler version: 7 (51.0) JD-Core Version: 0.7.1 + */ \ No newline at end of file diff --git a/src/main/java/org/greensky/platformjump/PlatformJumpCommandExecutor.java b/src/main/java/org/greensky/platformjump/PlatformJumpCommandExecutor.java index 8bb9621..7a2b226 100644 --- a/src/main/java/org/greensky/platformjump/PlatformJumpCommandExecutor.java +++ b/src/main/java/org/greensky/platformjump/PlatformJumpCommandExecutor.java @@ -1,47 +1,100 @@ -package org.greensky.platformjump; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class PlatformJumpCommandExecutor implements CommandExecutor { - private final PlatformJump plugin; - - public PlatformJumpCommandExecutor(PlatformJump plugin) { - this.plugin = plugin; // Store the plug-in in situations where you need - // it. - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, - String[] args) { - if (args.length == 0) { - return false; - } - switch (args[0].toLowerCase()) { - case "reload": - if (sender.hasPermission("platform.command.reload")) { - plugin.reloadConfig(); - sender.sendMessage("PlatformJump configuration reloaded"); - } else { - sender.sendMessage("No permission"); - } - return true; - case "toggle": - if (sender instanceof Player) { - if (sender.hasPermission("platform.command.toggle")) { - - plugin.togglePluginState((Player) sender); - } else { - sender.sendMessage("No permission"); - } - } else { - sender.sendMessage("You are not a player"); - } - - return true; - } - return false; - } -} +package org.greensky.platformjump; + +import org.bukkit.block.Block; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class PlatformJumpCommandExecutor implements org.bukkit.command.CommandExecutor { + private final PlatformJump plugin; + private Configuration configuration; + + public PlatformJumpCommandExecutor(PlatformJump plugin) { + this.plugin = plugin; + + this.configuration = plugin.getConfiguration(); + } + + public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) { + if (args.length == 0) + return false; + String str = args[0].toLowerCase(); + switch ((str)) { + case "reload": + if (sender.hasPermission("platform.command.reload")) { + for (Player eachPlayer : org.bukkit.Bukkit.getServer().getOnlinePlayers()) { + + if (this.plugin.getLastPlatformMap().containsKey(eachPlayer.getName())) { + ((Block) this.plugin.getLastPlatformMap().get(eachPlayer.getName())) + .setType(org.bukkit.Material.AIR); + this.plugin.getLastPlatformMap().remove(eachPlayer.getName()); + } + } + + this.plugin.reloadConfig(); + this.configuration.reload(); + this.plugin.getLogger().info("Platform Material: " + this.configuration.getPlatformMaterial()); + sender.sendMessage(this.plugin.getConfig().getString("message.reloaded")); + } else { + sender.sendMessage(this.plugin.getConfig().getString("message.no-permission")); + } + return true; + case "remove": + if (args.length == 1) { + if ((sender instanceof Player)) { + if (sender.hasPermission("platform.command.remove.self")) { + Player player = (Player) sender; + + if (this.plugin.getLastPlatformMap().containsKey(player.getName())) { + ((Block) this.plugin.getLastPlatformMap().get(player.getName())) + .setType(org.bukkit.Material.AIR); + this.plugin.getLastPlatformMap().remove(player.getName()); + sender.sendMessage(this.plugin.getConfig().getString("message.removed")); + } + } else { + sender.sendMessage(this.plugin.getConfig().getString("message.no-permission")); + } + } else { + sender.sendMessage(this.plugin.getConfig().getString("message.not-player")); + } + return true; + } + if (sender.hasPermission("platform.command.remove.others")) { + @SuppressWarnings("deprecation") + Player target = sender.getServer().getPlayer(args[1]); + + if (target == null) { + sender.sendMessage(args[1] + this.plugin.getConfig().getString("message.not-available")); + return true; + } + if (this.plugin.getLastPlatformMap().containsKey(target.getName())) { + ((Block) this.plugin.getLastPlatformMap().get(target.getName())).setType(org.bukkit.Material.AIR); + this.plugin.getLastPlatformMap().remove(target.getName()); + sender.sendMessage(this.plugin.getConfig().getString("message.removed")); + } + return true; + } + sender.sendMessage(this.plugin.getConfig().getString("message.no-permission")); + break; + case "toggle": + if ((sender instanceof Player)) { + if (sender.hasPermission("platform.command.toggle")) { + this.plugin.togglePluginState((Player) sender); + } else { + sender.sendMessage(this.plugin.getConfig().getString("message.no-permission")); + } + } else { + sender.sendMessage(this.plugin.getConfig().getString("message.not-player")); + } + + return true; + } + return false; + } +} + +/* + * Location: C:\Users\Henry + * Hu\Documents\plugins\PlatformJump-0.2.0.jar!\org\greensky\platformjump\ + * PlatformJumpCommandExecutor.class Java compiler version: 7 (51.0) JD-Core + * Version: 0.7.1 + */ \ No newline at end of file diff --git a/src/main/java/org/greensky/platformjump/PlatformJumpListener.java b/src/main/java/org/greensky/platformjump/PlatformJumpListener.java index 1f6ccf1..f56a315 100644 --- a/src/main/java/org/greensky/platformjump/PlatformJumpListener.java +++ b/src/main/java/org/greensky/platformjump/PlatformJumpListener.java @@ -1,124 +1,155 @@ -package org.greensky.platformjump; - -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.Effect; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -public class PlatformJumpListener implements Listener { - private Map lastPlatformMap; - private final PlatformJump plugin; - private boolean isDebugOn; - - public PlatformJumpListener(PlatformJump plugin) { - this.plugin = plugin; // Store the plug-in in situations where you need - // it. - lastPlatformMap = plugin.getLastPlatformMap(); - isDebugOn = plugin.getConfig().getBoolean("debug"); - } - - @EventHandler(priority = EventPriority.HIGH) - public void onBlockDispenseEvent(BlockBreakEvent event) { - isDebugOn = plugin.getConfig().getBoolean("debug"); - if (event.getBlock().getType() == Material.GLASS) { - if (lastPlatformMap.containsValue(event.getBlock())) { - // Cancel the break event to avoid drop - event.setCancelled(true); - - event.getBlock().setType(Material.AIR); - - if (isDebugOn) { - event.getPlayer().sendMessage("Drop cleared"); - } - } - - } - - } - - @EventHandler - public void onPlayerQuitEvent(PlayerQuitEvent event) { - Block lastPlatform = lastPlatformMap.get(event.getPlayer().getName()); - // Check the Material of the platform block - if (lastPlatform.getType() == Material.GLASS) { - lastPlatform.setType(Material.AIR); - lastPlatformMap.remove(event.getPlayer().getName()); - } - } - - @EventHandler - public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { - isDebugOn = plugin.getConfig().getBoolean("debug"); - Player player = event.getPlayer(); - // Check if player has permission. - String playerName = player.getName(); - if (plugin.getPluginEnabled(playerName)) { - // Check if player is sneaking - if (event.isSneaking()) { - // Check if player is flying - if (!player.isFlying()) { - // Check if player has permission - if (player.hasPermission("platform.create")) { - int platformMaxHeight = plugin.getConfig().getInt( - "platform.max-height"); - if (player.getLocation().getY() - 1 <= platformMaxHeight) { - Platform platform = new Platform(player); - platform.setLastPlatformMap(lastPlatformMap); - platform.setDebugOn(isDebugOn); - if (platform.createPlatform()) { - // Play particle to all the players - for (Player eachPlayer : Bukkit.getServer() - .getOnlinePlayers()) { - eachPlayer.playEffect(player.getLocation(), - Effect.ENDER_SIGNAL, null); - } - float exhaustionAdd = (float) plugin - .getConfig().getDouble("food-cost"); - player.setExhaustion(player.getExhaustion() - + exhaustionAdd); - if (isDebugOn) { - player.sendMessage("Current exhaustion: " - + player.getExhaustion()); - } - } - - } else { - player.sendMessage("can't create platform in this height"); - - } - - int jumpEffectTime = plugin.getConfig().getInt( - "jump-effect.time"); - if (isDebugOn) { - player.sendMessage("time:" + jumpEffectTime); - } - int jumpEffectLevel = plugin.getConfig().getInt( - "jump-effect.level"); - if (isDebugOn) { - player.sendMessage("level:" + jumpEffectLevel); - } - PotionEffect jumpEffect = new PotionEffect( - PotionEffectType.JUMP, jumpEffectTime, - jumpEffectLevel); - // add the jump effect to player - player.addPotionEffect(jumpEffect, true); - - } - } - } - } - - } - -} +package org.greensky.platformjump; + +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.potion.PotionEffect; + +public class PlatformJumpListener implements Listener { + private Map lastPlatformMap; + private final PlatformJump plugin; + private Configuration configuration; + + public PlatformJumpListener(PlatformJump plugin) { + this.plugin = plugin; + + this.lastPlatformMap = plugin.getLastPlatformMap(); + this.configuration = plugin.getConfiguration(); + if (this.configuration.isDebugOn()) { + plugin.getLogger().info("Listener Platform Material: " + this.configuration.getPlatformMaterial()); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void onBlockBreakEvent(BlockBreakEvent event) { + if ((event.getBlock().getType() == this.configuration.getPlatformMaterial()) + && (this.lastPlatformMap.containsValue(event.getBlock()))) { + event.setCancelled(true); + + event.getBlock().setType(Material.AIR); + + if (this.configuration.isDebugOn()) { + event.getPlayer().sendMessage("Drop cleared"); + } + } + } + + @EventHandler + public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { + Player player = event.getPlayer(); + + String playerName = player.getName(); + if (this.plugin.getPluginEnabled(playerName)) { + if (event.isSneaking()) { + if (!player.isFlying()) { + if (player.hasPermission("platform.create")) { + int platformMaxHeight = this.plugin.getConfig().getInt("platform.max-height"); + if (player.getLocation().getY() - 1.0D <= platformMaxHeight) { + Platform platform = new Platform(player); + platform.setLastPlatformMap(this.lastPlatformMap); + platform.setPlatformMaterial(this.configuration.getPlatformMaterial()); + platform.setDebugOn(this.configuration.isDebugOn()); + if (platform.createPlatform()) { + for (Player eachPlayer : org.bukkit.Bukkit.getServer().getOnlinePlayers()) { + eachPlayer.playEffect(player.getLocation(), org.bukkit.Effect.ENDER_SIGNAL, null); + } + float exhaustionAdd = (float) this.plugin.getConfig().getDouble("exhaustion"); + player.setExhaustion(player.getExhaustion() + exhaustionAdd); + if (this.configuration.isDebugOn()) { + player.sendMessage("Current exhaustion: " + player.getExhaustion()); + } + } else { + this.lastPlatformMap.remove(playerName); + } + } else { + player.sendMessage(this.plugin.getConfig().getString("message.too-high")); + } + + int jumpEffectTime = this.plugin.getConfig().getInt("jump-effect.time"); + if (this.configuration.isDebugOn()) { + player.sendMessage("time:" + jumpEffectTime); + } + int jumpEffectLevel = this.plugin.getConfig().getInt("jump-effect.level"); + if (this.configuration.isDebugOn()) { + player.sendMessage("level:" + jumpEffectLevel); + } + PotionEffect jumpEffect = new PotionEffect(org.bukkit.potion.PotionEffectType.JUMP, + jumpEffectTime, jumpEffectLevel); + + player.addPotionEffect(jumpEffect, true); + } + } + } + } + } + + @EventHandler + public void onEntityDamageEvent(EntityDamageEvent event) { + if (event.getCause() == org.bukkit.event.entity.EntityDamageEvent.DamageCause.FALL) { + org.bukkit.entity.Entity entity = event.getEntity(); + if ((entity instanceof Player)) { + Player player = (Player) entity; + if (this.lastPlatformMap.containsKey(player.getName())) { + Location playerLocation = player.getLocation(); + + playerLocation.setY(playerLocation.getY() - 1.0D); + if (this.configuration.isDebugOn()) { + player.sendMessage("The height of one block under you is " + playerLocation.getBlock().getY()); + player.sendMessage("The height of your last platform is " + + ((Block) this.lastPlatformMap.get(player.getName())).getY()); + } + + if (playerLocation.getBlock().equals(this.lastPlatformMap.get(player.getName()))) { + event.setCancelled(true); + } + } + } + } + } + + @EventHandler + public void onBlockPistonExtendEvent(BlockPistonExtendEvent event) { + for (Block eachBlock : event.getBlocks()) { + if ((eachBlock.getType() == this.configuration.getPlatformMaterial()) + && (this.lastPlatformMap.containsValue(eachBlock))) { + eachBlock.setType(Material.AIR); + if (this.configuration.isDebugOn()) { + this.plugin.getLogger().info("Piston extend: " + eachBlock.getType()); + } + } + } + } + + @EventHandler + public void onBlockPistonRetractEvent(BlockPistonRetractEvent event) { + @SuppressWarnings("deprecation") + Block platform = event.getRetractLocation().getBlock(); + if (platform.getType() == this.configuration.getPlatformMaterial()) { + if (this.lastPlatformMap.containsValue(platform)) { + event.setCancelled(true); + platform.setType(Material.AIR); + if (this.configuration.isDebugOn()) { + this.plugin.getLogger().info("Piston retract: " + platform.getType()); + } + } + } + } +} + +/* + * Location: C:\Users\Henry + * Hu\Documents\plugins\PlatformJump-0.2.0.jar!\org\greensky\platformjump\ + * PlatformJumpListener.class Java compiler version: 7 (51.0) JD-Core Version: + * 0.7.1 + */ \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 08146b2..2728944 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,10 +1,24 @@ -platform: - max-height: 256 - # Set the max height where platforms can be created. -jump-effect: - time: 200 - # Set the time of the effect of jump. - level: 4 - # Set the level of the effect of jump. -food-cost: 1 -debug: false +platform: + block-id: 20 + max-height: 256 + # Set the max height where platforms can be created. +jump-effect: + time: 200 + # Set the time of the effect of jump. + level: 4 + # Set the level of the effect of jump. +exhaustion: 1 +# Add exhaustion of hunger when creating platforms +debug: false +metrics: true +# Set true if agree to send data to mcstats.org +message: + no-permission: No permission + too-high: can't create platform in this height + reloaded: PlatformJump configuration reloaded + toggle-on: PlatformJump enabled + toggle-off: PlatformJump disabled + removed: Last platform removed + not-available: is not currently available + not-player: You are not a player +version: 0.2.0 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index da64291..a7c0d3a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,43 +1,58 @@ -name: PlatformJump -main: org.greensky.platformjump.PlatformJump -version: 0.0.6-SNAPSHOT -author: Henry5041 -permissions: - platform.*: - description: Allows you to use all platform feature - default: op - children: - platform.admin: true - platform.use: true - platform.use: - description: The basic feature of platform - default: false - children: - platform.create: true - platform.command.toggle: true - platform.admin: - description: The feature for administrators - default: op - children: - platform.command.*: true - platform.create: - description: Allows you to create platform - default: false - platform.command.*: - description: Allows you to use command - default: op - children: - platform.command.toggle: true - platform.command.reload: true - platform.command.toggle: - description: Allows you to use command toggle - default: true - platform.command.reload: - description: Allows you to use command reload - default: op -commands: - platform: - description: This is the main command of PlatformJump. - usage: | - / reload - reloads the configuration - / toggle - Allows you to toggle enabled of platform +name: PlatformJump +main: org.greensky.platformjump.PlatformJump +version: 0.2.0 +author: Henry5041 +permissions: + platform.*: + description: Allows you to use all platform feature + default: op + children: + platform.admin: true + platform.use: true + platform.use: + description: The basic feature of platform + default: false + children: + platform.create: true + platform.command.toggle: true + platform.command.remove.self: true + platform.admin: + description: The feature for administrators + default: op + children: + platform.command.*: true + platform.create: + description: Allows you to create platform + default: false + platform.command.*: + description: Allows you to use command + default: op + children: + platform.command.toggle: true + platform.command.reload: true + platform.command.remove.*: true + platform.command.toggle: + description: Allows you to use command toggle + default: false + platform.command.reload: + description: Allows you to use command reload + default: op + platform.command.remove.*: + description: Allows you to use command remove + default: op + children: + platform.command.remove.self: true + platform.command.remove.others: true + platform.command.remove.self: + description: Allows you to use command remove to yourself + default: false + platform.command.remove.others: + description: Allows you to use command remove to others + default: op +commands: + platform: + description: This is the main command of PlatformJump. + usage: | + / reload - reloads the configuration + / toggle - Allows you to toggle enabled of platform + / remove - Allows you to remove your last platform \ No newline at end of file diff --git a/src/test/java/org/greensky/platformjump/PlatformJumpTest.java b/src/test/java/org/greensky/platformjump/PlatformJumpTest.java index 27576c9..26180b5 100644 --- a/src/test/java/org/greensky/platformjump/PlatformJumpTest.java +++ b/src/test/java/org/greensky/platformjump/PlatformJumpTest.java @@ -13,7 +13,7 @@ public void setUp() throws Exception { @Test public void testOnEnable() { - + } }