mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-24 17:47:44 +01:00
Request on bukkit forums, I don't plan to update this. Feel free to use the code however you wish.
This commit is contained in:
parent
f50a3ae6a2
commit
7627b7f7e4
7
BackOff/.classpath
Normal file
7
BackOff/.classpath
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||||
|
<classpathentry kind="lib" path="C:/MC Server/bukkit.jar"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
17
BackOff/.project
Normal file
17
BackOff/.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>BackOff</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
12
BackOff/.settings/org.eclipse.jdt.core.prefs
Normal file
12
BackOff/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -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
|
BIN
BackOff/bin/com/bukkit/nossr50/BackOff/BackOff.class
Normal file
BIN
BackOff/bin/com/bukkit/nossr50/BackOff/BackOff.class
Normal file
Binary file not shown.
BIN
BackOff/bin/com/bukkit/nossr50/BackOff/bPlayerListener.class
Normal file
BIN
BackOff/bin/com/bukkit/nossr50/BackOff/bPlayerListener.class
Normal file
Binary file not shown.
3
BackOff/bin/plugin.yml
Normal file
3
BackOff/bin/plugin.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name: BackOff
|
||||||
|
main: com.bukkit.nossr50.BackOff.BackOff
|
||||||
|
version: 1.0
|
41
BackOff/src/com/bukkit/nossr50/BackOff/BackOff.java
Normal file
41
BackOff/src/com/bukkit/nossr50/BackOff/BackOff.java
Normal file
@ -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<Player, Boolean> debugees = new HashMap<Player, Boolean>();
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
107
BackOff/src/com/bukkit/nossr50/BackOff/bPlayerListener.java
Normal file
107
BackOff/src/com/bukkit/nossr50/BackOff/bPlayerListener.java
Normal file
@ -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<String> backOffList = new ArrayList<String>();
|
||||||
|
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<String> ibackOffList = new ArrayList<String>();
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
3
BackOff/src/plugin.yml
Normal file
3
BackOff/src/plugin.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name: BackOff
|
||||||
|
main: com.bukkit.nossr50.BackOff.BackOff
|
||||||
|
version: 1.0
|
Loading…
Reference in New Issue
Block a user