Ce dev aime les TAB --"
This commit is contained in:
parent
7eab05fc78
commit
1975864afb
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
* Copyright 2012 by JFK - whydontyouspamme@hotmail.com
|
* Copyright 2012 by JFK - whydontyouspamme@hotmail.com
|
||||||
* Original Code by: nisovin
|
* Original Code by: nisovin
|
||||||
@ -30,12 +30,12 @@ import org.bukkit.util.Vector;
|
|||||||
public class BallPlayerListener implements Listener {
|
public class BallPlayerListener implements Listener {
|
||||||
|
|
||||||
CraftBall plugin;
|
CraftBall plugin;
|
||||||
|
|
||||||
public BallPlayerListener(CraftBall plugin) {
|
public BallPlayerListener(CraftBall plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||||
Item item = event.getItem();
|
Item item = event.getItem();
|
||||||
@ -46,7 +46,7 @@ public class BallPlayerListener implements Listener {
|
|||||||
Vector v = item.getLocation().toVector().subtract(player.getLocation().toVector()).normalize().multiply(field.hKickPower);
|
Vector v = item.getLocation().toVector().subtract(player.getLocation().toVector()).normalize().multiply(field.hKickPower);
|
||||||
v.setY(field.vKickPower);
|
v.setY(field.vKickPower);
|
||||||
item.setVelocity(v);
|
item.setVelocity(v);
|
||||||
if (field.fire) {
|
if (field.fire) {
|
||||||
item.setFireTicks(6000);
|
item.setFireTicks(6000);
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -54,7 +54,7 @@ public class BallPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
Item item = event.getItemDrop();
|
Item item = event.getItemDrop();
|
||||||
@ -63,7 +63,7 @@ public class BallPlayerListener implements Listener {
|
|||||||
plugin.log_debug("Player "+event.getPlayer().getName()+" threw trow-able item in field");
|
plugin.log_debug("Player "+event.getPlayer().getName()+" threw trow-able item in field");
|
||||||
item.setPickupDelay(field.pickupDelay);
|
item.setPickupDelay(field.pickupDelay);
|
||||||
item.setVelocity(event.getPlayer().getLocation().getDirection().normalize().multiply(field.throwPower));
|
item.setVelocity(event.getPlayer().getLocation().getDirection().normalize().multiply(field.throwPower));
|
||||||
if (field.fire) {
|
if (field.fire) {
|
||||||
item.setFireTicks(6000);
|
item.setFireTicks(6000);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
* Copyright 2012 by JFK - whydontyouspamme@hotmail.com
|
* Copyright 2012 by JFK - whydontyouspamme@hotmail.com
|
||||||
* Original Code by: nisovin
|
* Original Code by: nisovin
|
||||||
@ -38,21 +38,21 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
|
|
||||||
public class CraftBall extends JavaPlugin implements CommandExecutor {
|
public class CraftBall extends JavaPlugin implements CommandExecutor {
|
||||||
|
|
||||||
protected HashSet<Field> fields = new HashSet<Field>();
|
protected HashSet<Field> fields = new HashSet<Field>();
|
||||||
|
|
||||||
private boolean DEBUG = false;
|
private boolean DEBUG = false;
|
||||||
private String TAG = "[CBall]";
|
private String TAG = "[CBall]";
|
||||||
|
|
||||||
private Logger mclog = Logger.getLogger("Minecraft");
|
private Logger mclog = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
new BallPlayerListener(this);
|
new BallPlayerListener(this);
|
||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
log_info("CraftBall v" + this.getDescription().getVersion() + " enabled: " + fields.size() + " fields loaded.");
|
log_info("CraftBall v" + this.getDescription().getVersion() + " enabled: " + fields.size() + " fields loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,92 +61,92 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
sendMess("commands: '/cb reload' '/cb list'", sender);
|
sendMess("commands: '/cb reload' '/cb list'", sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].toLowerCase().equals("reload")) {
|
if (args[0].toLowerCase().equals("reload")) {
|
||||||
fields.clear();
|
fields.clear();
|
||||||
loadConfig();
|
loadConfig();
|
||||||
sendMess("CraftBall config reloaded.", sender);
|
sendMess("CraftBall config reloaded.", sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].toLowerCase().equals("list")) {
|
if (args[0].toLowerCase().equals("list")) {
|
||||||
for (Field f : fields) {
|
for (Field f : fields) {
|
||||||
sendMess("-----Field: "+f.name, sender);
|
sendMess("-----Field: "+f.name, sender);
|
||||||
sendMess("-World: "+ f.world.getName(), sender);
|
sendMess("-World: "+ f.world.getName(), sender);
|
||||||
sendMess("-Region: (x,z)", sender);
|
sendMess("-Region: (x,z)", sender);
|
||||||
for (int i=0; i < f.region.npoints; i++) {
|
for (int i=0; i < f.region.npoints; i++) {
|
||||||
sendMess(" -("+f.region.xpoints[i]+","+f.region.ypoints[i]+")", sender);
|
sendMess(" -("+f.region.xpoints[i]+","+f.region.ypoints[i]+")", sender);
|
||||||
}
|
}
|
||||||
sendMess("-BallItem: "+f.ballItem.getType().toString(), sender);
|
sendMess("-BallItem: "+f.ballItem.getType().toString(), sender);
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") //for Fieldlist, can hardly go wrong and put a try/catch over it
|
@SuppressWarnings("unchecked") //for Fieldlist, can hardly go wrong and put a try/catch over it
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
|
|
||||||
//see if datafolder exists, else copy default config.yml
|
//see if datafolder exists, else copy default config.yml
|
||||||
if (!this.getDataFolder().exists()) {
|
if (!this.getDataFolder().exists()) {
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
|
|
||||||
if (updateConfig()) {
|
if (updateConfig()) {
|
||||||
log_info("Succesfully updated config.yml");
|
log_info("Succesfully updated config.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getConfig().get("fields") == null) {
|
if (getConfig().get("fields") == null) {
|
||||||
fatal("Error no fields found in config.yml");
|
fatal("Error no fields found in config.yml");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map<?, ?>> fieldList = getConfig().getMapList("fields");
|
List<Map<?, ?>> fieldList = getConfig().getMapList("fields");
|
||||||
int fieldCount = 0;
|
int fieldCount = 0;
|
||||||
|
|
||||||
for (Map<?, ?> f : fieldList) {
|
for (Map<?, ?> f : fieldList) {
|
||||||
Field field = new Field();
|
Field field = new Field();
|
||||||
fieldCount++;
|
fieldCount++;
|
||||||
|
|
||||||
if (f.get("name") == null || !(f.get("name") instanceof String)) {
|
if (f.get("name") == null || !(f.get("name") instanceof String)) {
|
||||||
field.name = "no_name"+fieldCount;
|
field.name = "no_name"+fieldCount;
|
||||||
} else {
|
} else {
|
||||||
field.name = (String) f.get("name");
|
field.name = (String) f.get("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (f.get("world") == null || !(f.get("world") instanceof String)) {
|
if (f.get("world") == null || !(f.get("world") instanceof String)) {
|
||||||
log_warning("Error found in field list: world not found, using default");
|
log_warning("Error found in field list: world not found, using default");
|
||||||
field.world = getServer().getWorlds().get(0);
|
field.world = getServer().getWorlds().get(0);
|
||||||
} else {
|
} else {
|
||||||
if (getServer().getWorld((String) f.get("world")) == null) {
|
if (getServer().getWorld((String) f.get("world")) == null) {
|
||||||
log_warning("Error found in field list: world not found, using default");
|
log_warning("Error found in field list: world not found, using default");
|
||||||
field.world = getServer().getWorlds().get(0);
|
field.world = getServer().getWorlds().get(0);
|
||||||
} else {
|
} else {
|
||||||
field.world = getServer().getWorld((String) f.get("world"));
|
field.world = getServer().getWorld((String) f.get("world"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get region
|
// get region
|
||||||
List<String> points = null;
|
List<String> points = null;
|
||||||
//points = node.getStringList("region");
|
//points = node.getStringList("region");
|
||||||
if (f.get("region") == null || !(f.get("region") instanceof List <?>)) {
|
if (f.get("region") == null || !(f.get("region") instanceof List <?>)) {
|
||||||
log_warning("Error found in field list: could not find region");
|
log_warning("Error found in field list: could not find region");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
points = (List <String>) f.get("region");
|
points = (List <String>) f.get("region");
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
points = null;
|
points = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (points == null) {
|
if (points == null) {
|
||||||
log_warning("Error found in field list: some error in region");
|
log_warning("Error found in field list: some error in region");
|
||||||
continue;
|
continue;
|
||||||
@ -156,11 +156,11 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
field.region.addPoint(Integer.parseInt(point[0]), Integer.parseInt(point[1]));
|
field.region.addPoint(Integer.parseInt(point[0]), Integer.parseInt(point[1]));
|
||||||
}
|
}
|
||||||
if (f.get("region-y") == null || !(f.get("region-y") instanceof Integer)) {
|
if (f.get("region-y") == null || !(f.get("region-y") instanceof Integer)) {
|
||||||
field.fieldY = 64;
|
field.fieldY = 64;
|
||||||
} else {
|
} else {
|
||||||
field.fieldY = (Integer) f.get("region-y");
|
field.fieldY = (Integer) f.get("region-y");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.get("field-height") == null || !(f.get("field-height") instanceof Integer)) {
|
if (f.get("field-height") == null || !(f.get("field-height") instanceof Integer)) {
|
||||||
field.fieldHeight = 4;
|
field.fieldHeight = 4;
|
||||||
} else {
|
} else {
|
||||||
@ -168,10 +168,10 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (f.get("ball-item") == null || !(f.get("ball-item") instanceof String || f.get("ball-item") instanceof Integer)) {
|
if (f.get("ball-item") == null || !(f.get("ball-item") instanceof String || f.get("ball-item") instanceof Integer)) {
|
||||||
log_warning("Error found in field list: could not find ball-item");
|
log_warning("Error found in field list: could not find ball-item");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ball item
|
// ball item
|
||||||
String ballItem = f.get("ball-item").toString();
|
String ballItem = f.get("ball-item").toString();
|
||||||
if (ballItem.contains(":")) {
|
if (ballItem.contains(":")) {
|
||||||
@ -180,7 +180,7 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
field.ballItem = new ItemStack(Integer.parseInt(ballItem));
|
field.ballItem = new ItemStack(Integer.parseInt(ballItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
// kick options
|
// kick options
|
||||||
if (f.get("enable-kick") == null || !(f.get("enable-kick") instanceof Boolean)) {
|
if (f.get("enable-kick") == null || !(f.get("enable-kick") instanceof Boolean)) {
|
||||||
field.enableKick = true;
|
field.enableKick = true;
|
||||||
@ -208,8 +208,8 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
field.throwPower = 0.5;
|
field.throwPower = 0.5;
|
||||||
} else {
|
} else {
|
||||||
field.throwPower = (Double) f.get("throw-power");
|
field.throwPower = (Double) f.get("throw-power");
|
||||||
}
|
}
|
||||||
|
|
||||||
// misc options
|
// misc options
|
||||||
if (f.get("enable-fire") == null || !(f.get("enable-fire") instanceof Boolean)) {
|
if (f.get("enable-fire") == null || !(f.get("enable-fire") instanceof Boolean)) {
|
||||||
field.fire= false;
|
field.fire= false;
|
||||||
@ -221,19 +221,19 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
field.pickupDelay = (Integer) f.get("pickup-delay");
|
field.pickupDelay = (Integer) f.get("pickup-delay");
|
||||||
}
|
}
|
||||||
|
|
||||||
fields.add(field);
|
fields.add(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateConfig() {
|
public boolean updateConfig() {
|
||||||
if (getConfig().getString("version", null) != null &&
|
if (getConfig().getString("version", null) != null &&
|
||||||
getDescription().getVersion().equals(getConfig().getString("version"))
|
getDescription().getVersion().equals(getConfig().getString("version"))
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
@ -243,41 +243,41 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
BufferedReader cRead;
|
BufferedReader cRead;
|
||||||
FileOutputStream cOut;
|
FileOutputStream cOut;
|
||||||
StringBuffer cBuffer;
|
StringBuffer cBuffer;
|
||||||
|
|
||||||
//---readfile section
|
//---readfile section
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cFile = new File(getDataFolder()+File.separator+"config.yml");
|
cFile = new File(getDataFolder()+File.separator+"config.yml");
|
||||||
cRead = new BufferedReader(new InputStreamReader(new FileInputStream(cFile), "UTF-8"));
|
cRead = new BufferedReader(new InputStreamReader(new FileInputStream(cFile), "UTF-8"));
|
||||||
cBuffer = new StringBuffer();
|
cBuffer = new StringBuffer();
|
||||||
int ch;
|
int ch;
|
||||||
while ((ch = cRead.read()) > -1) {
|
while ((ch = cRead.read()) > -1) {
|
||||||
cBuffer.append((char)ch);
|
cBuffer.append((char)ch);
|
||||||
}
|
}
|
||||||
cString = cBuffer.toString();
|
cString = cBuffer.toString();
|
||||||
cRead.close();
|
cRead.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log_warning("Error, couldn't update/load config.yml:"+e.toString());
|
log_warning("Error, couldn't update/load config.yml:"+e.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cFile.exists()) {
|
if (!cFile.exists()) {
|
||||||
log_warning("Error, couldn't update config.yml, file not found.");
|
log_warning("Error, couldn't update config.yml, file not found.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//--- update sections:
|
//--- update sections:
|
||||||
oldV = getConfig().getString("version", null);
|
oldV = getConfig().getString("version", null);
|
||||||
//before 1.1
|
//before 1.1
|
||||||
//change list structure
|
//change list structure
|
||||||
//add world variable
|
//add world variable
|
||||||
//add name variable
|
//add name variable
|
||||||
if (oldV == null) {
|
if (oldV == null) {
|
||||||
cString = "version: 1.1\r".concat(cString);
|
cString = "version: 1.1\r".concat(cString);
|
||||||
cString = cString.replaceAll("(\\s{4}(field\\d+):)", " -\r name: $2\r world: "+getServer().getWorlds().get(0).getName());
|
cString = cString.replaceAll("(\\s{4}(field\\d+):)", " -\r name: $2\r world: "+getServer().getWorlds().get(0).getName());
|
||||||
log_warning("Updated config.yml from version <1.1, check your world settings in config.yml!");
|
log_warning("Updated config.yml from version <1.1, check your world settings in config.yml!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//--- writefile section
|
//--- writefile section
|
||||||
try {
|
try {
|
||||||
cOut = new FileOutputStream(cFile);
|
cOut = new FileOutputStream(cFile);
|
||||||
@ -289,34 +289,34 @@ public class CraftBall extends JavaPlugin implements CommandExecutor {
|
|||||||
log_warning("Error, couldn't update/save config.yml:"+e.toString());
|
log_warning("Error, couldn't update/save config.yml:"+e.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getConfig();
|
getConfig();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void sendMess(String msg, CommandSender sender) {
|
public void sendMess(String msg, CommandSender sender) {
|
||||||
sender.sendMessage(TAG+ " " + msg);
|
sender.sendMessage(TAG+ " " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log_info(String msg) {
|
public void log_info(String msg) {
|
||||||
mclog.info(TAG + " " + msg);
|
mclog.info(TAG + " " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void log_warning(String msg) {
|
public void log_warning(String msg) {
|
||||||
mclog.warning(TAG + " " + msg);
|
mclog.warning(TAG + " " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void log_debug(String msg) {
|
public void log_debug(String msg) {
|
||||||
if (DEBUG) {mclog.info(TAG + " DEBUG: " + msg);}
|
if (DEBUG) {mclog.info(TAG + " DEBUG: " + msg);}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fatal(String msg) {
|
public void fatal(String msg) {
|
||||||
mclog.severe(TAG + " " + msg);
|
mclog.severe(TAG + " " + msg);
|
||||||
this.getServer().getPluginManager().disablePlugin(this);
|
this.getServer().getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user