Initial commit
This commit is contained in:
commit
7cf3bd1b8c
7
.classpath
Normal file
7
.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="/home/ian/Desktop/minecraft server/craftbukkit-0.0.1-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
bin/
|
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>NoTNT</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
.settings/org.eclipse.jdt.core.prefs
Normal file
12
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,12 @@
|
||||
#Sat Jul 02 15:06:31 EDT 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
|
7
plugin.yml
Normal file
7
plugin.yml
Normal file
@ -0,0 +1,7 @@
|
||||
name: No TNT
|
||||
main: com.ianonavy.notnt.NoTNT
|
||||
version: 0.2
|
||||
website: http://ianonavy.freeiz.com
|
||||
description: Absolutely bans TNT throughout the server and sends users a configurable message. Works even with WorldEdit.
|
||||
authors: [ianonavy]
|
||||
commands:
|
123
src/com/ianonavy/notnt/NoTNT.java
Normal file
123
src/com/ianonavy/notnt/NoTNT.java
Normal file
@ -0,0 +1,123 @@
|
||||
package com.ianonavy.notnt;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
/**
|
||||
* Plugin for Minecraft Bukkit servers that bans the placing of TNT throughout the server.
|
||||
*
|
||||
* @author ianonavy
|
||||
* @version 0.2
|
||||
*/
|
||||
public class NoTNT extends JavaPlugin {
|
||||
|
||||
// Get the logger
|
||||
public final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
// Instance fields
|
||||
public NoTNTExplosionListener explosionListener;
|
||||
private String warning;
|
||||
|
||||
// Constants
|
||||
private final String DEFAULT_MESSAGE = "WARNING: TNT attempted to explode at {x}, {y}, {z}. Players nearby: {playerlist}";
|
||||
|
||||
/**
|
||||
* Constrcutor for the No TNT plugin.
|
||||
*/
|
||||
public NoTNT() {
|
||||
explosionListener = new NoTNTExplosionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the plugin is disabled.
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.logger.info("No TNT disabled.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the plugin is enabled.
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.explosionListener, Event.Priority.High, this);
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
loadConfiguration();
|
||||
this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " enabled.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the configuration files. If they are missing, it creates them with the default files.
|
||||
*/
|
||||
public void loadConfiguration() {
|
||||
// Load the config as a Java file.
|
||||
String directory = getDataFolder().getPath();
|
||||
File configYML = new File(directory + File.separator + "config.yml");
|
||||
|
||||
// Recreate the directory just in case it got deleted or for when the plugin is
|
||||
// first installed.
|
||||
new File(directory).mkdir();
|
||||
|
||||
// If the config file is missing...
|
||||
if (!configYML.exists()) {
|
||||
|
||||
// ...create the file and catch any errors.
|
||||
try {
|
||||
configYML.createNewFile();
|
||||
this.logger.info("No TNT: config.yml file missing! Generating new one...");
|
||||
|
||||
// Set the message to the
|
||||
getConfiguration().setProperty("notnt.warning", DEFAULT_MESSAGE);
|
||||
} catch (Exception e) {
|
||||
// Print any exceptions.
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
// If the config file exists...
|
||||
this.logger.info("No TNT: Loading config.yml...");
|
||||
|
||||
try {
|
||||
// ...load it.
|
||||
Configuration config = new Configuration(configYML);
|
||||
config.load();
|
||||
|
||||
// If the file is blank or missing the warning configuration,
|
||||
if (config.getString("notnt.warning") == null) {
|
||||
// Set it to the default one and save it.
|
||||
config.setProperty("notnt.warning", DEFAULT_MESSAGE);
|
||||
config.save();
|
||||
}
|
||||
|
||||
// Set the instance field for the warning.
|
||||
setWarning(config.getString("notnt.warning"));
|
||||
} catch (Exception e) {
|
||||
// Print any exceptions.
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the warning message instance field for the block listener.
|
||||
* @param s the string to set it to
|
||||
*/
|
||||
public void setWarning(String s) {
|
||||
warning = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the warning message as a string for the block listener.
|
||||
* @return the warning message as a string
|
||||
*/
|
||||
public String getWarning() {
|
||||
return warning;
|
||||
}
|
||||
}
|
58
src/com/ianonavy/notnt/NoTNTExplosionListener.java
Normal file
58
src/com/ianonavy/notnt/NoTNTExplosionListener.java
Normal file
@ -0,0 +1,58 @@
|
||||
package com.ianonavy.notnt;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
/**
|
||||
* Entity explosion listener for the No TNT plugin.
|
||||
* @author ianonavy
|
||||
* @version 0.2
|
||||
*/
|
||||
public class NoTNTExplosionListener extends EntityListener {
|
||||
// Instance field
|
||||
public static NoTNT plugin;
|
||||
|
||||
/**
|
||||
* Constructor for the No TNT block listener. Retrieves the instance of the main class.
|
||||
* @param instance
|
||||
*/
|
||||
public NoTNTExplosionListener(NoTNT instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for explosions
|
||||
*/
|
||||
public void onEntityExplosion(EntityExplodeEvent event) {
|
||||
if (event.getEntity().getClass() == TNTPrimed.class) {
|
||||
event.setCancelled(true);
|
||||
|
||||
String warning = plugin.getWarning();
|
||||
|
||||
double x = event.getLocation().getBlockX();
|
||||
double y = event.getLocation().getBlockX();
|
||||
double z = event.getLocation().getBlockX();
|
||||
int range = 10;
|
||||
|
||||
String playerList = "";
|
||||
for (Player player : event.getLocation().getWorld().getPlayers()) {
|
||||
Location playerLoc = player.getLocation();
|
||||
if (playerLoc.getX() - x < range ||
|
||||
playerLoc.getY() - y < range ||
|
||||
playerLoc.getZ() - z < range) {
|
||||
playerList = playerList + player.getDisplayName() + " ";
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getServer().broadcastMessage(
|
||||
warning.replaceFirst("{x}", x + "")
|
||||
.replaceFirst("{y}", y + "")
|
||||
.replaceFirst("{z}", z + "")
|
||||
.replaceFirst("{playerlist}", playerList)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user