diff --git a/BackOff/.classpath b/BackOff/.classpath new file mode 100644 index 000000000..c7455396a --- /dev/null +++ b/BackOff/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/BackOff/.project b/BackOff/.project new file mode 100644 index 000000000..9a37bd8d7 --- /dev/null +++ b/BackOff/.project @@ -0,0 +1,17 @@ + + + BackOff + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/BackOff/.settings/org.eclipse.jdt.core.prefs b/BackOff/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..ee0c391d9 --- /dev/null +++ b/BackOff/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Sat Feb 05 17:28:29 PST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/BackOff/bin/com/bukkit/nossr50/BackOff/BackOff.class b/BackOff/bin/com/bukkit/nossr50/BackOff/BackOff.class new file mode 100644 index 000000000..901ba79dc Binary files /dev/null and b/BackOff/bin/com/bukkit/nossr50/BackOff/BackOff.class differ diff --git a/BackOff/bin/com/bukkit/nossr50/BackOff/bPlayerListener.class b/BackOff/bin/com/bukkit/nossr50/BackOff/bPlayerListener.class new file mode 100644 index 000000000..3e37b6e31 Binary files /dev/null and b/BackOff/bin/com/bukkit/nossr50/BackOff/bPlayerListener.class differ diff --git a/BackOff/bin/plugin.yml b/BackOff/bin/plugin.yml new file mode 100644 index 000000000..f471fca9f --- /dev/null +++ b/BackOff/bin/plugin.yml @@ -0,0 +1,3 @@ +name: BackOff +main: com.bukkit.nossr50.BackOff.BackOff +version: 1.0 \ No newline at end of file diff --git a/BackOff/src/com/bukkit/nossr50/BackOff/BackOff.java b/BackOff/src/com/bukkit/nossr50/BackOff/BackOff.java new file mode 100644 index 000000000..7093b7dda --- /dev/null +++ b/BackOff/src/com/bukkit/nossr50/BackOff/BackOff.java @@ -0,0 +1,41 @@ +package com.bukkit.nossr50.BackOff; + +import java.io.File; +import java.util.HashMap; +import org.bukkit.event.player.*; +import org.bukkit.Server; +import org.bukkit.event.Event.Priority; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginLoader; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.entity.Player; + +/** + * BackOff for Bukkit + * + * @author nossr50 + */ +public class BackOff extends JavaPlugin { + private final bPlayerListener playerListener = new bPlayerListener(this); + private final HashMap debugees = new HashMap(); + private final String name = "BackOff"; + + public BackOff(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { + super(pluginLoader, instance, desc, folder, plugin, cLoader); + } + + public void onEnable() { + PluginManager pm = getServer().getPluginManager(); + pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this); + PluginDescriptionFile pdfFile = this.getDescription(); + System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); + } + public void onDisable() { + System.out.println("BackOff disabled."); + } +} + diff --git a/BackOff/src/com/bukkit/nossr50/BackOff/bPlayerListener.java b/BackOff/src/com/bukkit/nossr50/BackOff/bPlayerListener.java new file mode 100644 index 000000000..986d0e9d5 --- /dev/null +++ b/BackOff/src/com/bukkit/nossr50/BackOff/bPlayerListener.java @@ -0,0 +1,107 @@ +package com.bukkit.nossr50.BackOff; + +import java.util.ArrayList; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.event.player.PlayerListener; +import org.bukkit.event.player.PlayerMoveEvent; + +/** + * Handle events for all Player related events + * @author nossr50 + */ + + +public class bPlayerListener extends PlayerListener { + private final BackOff plugin; + + static ArrayList backOffList = new ArrayList(); + public boolean isBackOff(String playerName) {return backOffList.contains(playerName);} + public void removeBackOff(String playerName) {backOffList.remove(backOffList.indexOf(playerName));} + public void addBackOff(String playerName) {backOffList.add(playerName);} + static ArrayList ibackOffList = new ArrayList(); + public boolean isBackOffi(String playerName) {return ibackOffList.contains(playerName);} + public void removeBackOffi(String playerName) {ibackOffList.remove(backOffList.indexOf(playerName));} + public void addBackOffi(String playerName) {ibackOffList.add(playerName);} + + public static double getDistance(Player player1, Player player2) + { + return Math.sqrt(Math.pow(player1.getLocation().getX() - player2.getLocation().getX(), 2) + Math.pow(player1.getLocation().getY() - player2.getLocation().getY(), 2) + + Math.pow(player1.getLocation().getZ() - player2.getLocation().getZ(), 2)); + } + public static double getDistance(Location loc, Player player2) + { + return Math.sqrt(Math.pow(loc.getX() - player2.getLocation().getX(), 2) + Math.pow(loc.getY() - player2.getLocation().getY(), 2) + + Math.pow(loc.getZ() - player2.getLocation().getZ(), 2)); + } + + public bPlayerListener(BackOff instance) { + plugin = instance; + } + public boolean isPlayer(String playerName){ + for(Player herp : plugin.getServer().getOnlinePlayers()){ + if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){ + return true; + } + } + return false; + } + public Player getPlayer(String playerName){ + for(Player herp : plugin.getServer().getOnlinePlayers()){ + if(herp.getName().toLowerCase().equals(playerName.toLowerCase())){ + return herp; + } + } + return null; + } + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); + Location to = event.getTo(); + Location from = event.getFrom(); + for (Player derp : plugin.getServer().getOnlinePlayers()){ + if(isBackOff(derp.getName()) && !isBackOffi(player.getName())){ + if(player != derp && (getDistance(player, derp) < 7)){ + if(getDistance(to, derp) > getDistance(from, derp)){ + player.teleportTo(event.getFrom()); + } + } + } + } + } + public void onPlayerCommand(PlayerChatEvent event){ + String[] split = event.getMessage().split(" "); + Player player = event.getPlayer(); + if(player.isOp() && split[0].equalsIgnoreCase("/backoff")){ + if(split.length == 1){ + if(isBackOff(player.getName())){ + removeBackOff(player.getName()); + player.sendMessage("Back off mode disabled"); + return; + } else{ + addBackOff(player.getName()); + player.sendMessage("Back off mode enabled"); + return; + } + } + if(isPlayer(split[1])){ + Player target = getPlayer(split[1]); + if(isBackOffi(target.getName())){ + removeBackOffi(target.getName()); + target.sendMessage("Removed from back off mode immunity"); + if(!target.getName().equals(player.getName())) + player.sendMessage("Removed " + target.getName() + " from back off mode"); + } else { + addBackOffi(target.getName()); + target.sendMessage("Added to back off mode immunity"); + if(!target.getName().equals(player.getName())) + player.sendMessage("Added " + target.getName() + " from back off mode"); + } + } + } + } +} + diff --git a/BackOff/src/plugin.yml b/BackOff/src/plugin.yml new file mode 100644 index 000000000..f471fca9f --- /dev/null +++ b/BackOff/src/plugin.yml @@ -0,0 +1,3 @@ +name: BackOff +main: com.bukkit.nossr50.BackOff.BackOff +version: 1.0 \ No newline at end of file