mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-23 08:41:21 +01:00
Tidying up code to make it look like I'm actually doing something...
This commit is contained in:
parent
6fdd00724f
commit
4fb9098485
@ -4,27 +4,29 @@ import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
//import org.bukkit.event.block.BlockRightClickEvent;
|
||||
|
||||
public class MVBlockListener extends BlockListener {
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
|
||||
public MVBlockListener(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
//public void onBlockRightClicked(BlockRightClickEvent event){
|
||||
|
||||
//}
|
||||
|
||||
public void onBlockDamage(BlockDamageEvent event){
|
||||
|
||||
|
||||
// public void onBlockRightClicked(BlockRightClickEvent event){
|
||||
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
if(event.isCancelled())
|
||||
{
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -35,9 +37,9 @@ public class MVBlockListener extends BlockListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void onBlockPlaced(BlockPlaceEvent event){
|
||||
|
||||
|
||||
public void onBlockPlaced(BlockPlaceEvent event) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import org.bukkit.command.CommandSender;
|
||||
public abstract class MVCommandHandler {
|
||||
|
||||
protected final MultiVerseCore plugin;
|
||||
|
||||
public MVCommandHandler(MultiVerseCore plugin){
|
||||
|
||||
public MVCommandHandler(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
public abstract boolean perform(CommandSender sender, String[] args);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.CreatureType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.PigZombie;
|
||||
@ -19,52 +18,57 @@ import org.bukkit.event.entity.EntityDamageByProjectileEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
|
||||
//import org.bukkit.event.entity.ExplosionPrimedEvent;
|
||||
|
||||
public class MVEntityListener extends EntityListener {
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
|
||||
public MVEntityListener(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
// Need to find a way to stop the Ghast Fireballs damaging
|
||||
// Need to find a way to stop the Ghast Fireballs damaging
|
||||
// surroundings but still doing damage to players.
|
||||
public void onEntityExplode(EntityExplodeEvent event){
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
|
||||
}
|
||||
//public void onExplosionPrimed(ExplosionPrimedEvent event){
|
||||
//if(event.getEntity() instanceof Fireball){
|
||||
//MultiVerseCore.log.info();
|
||||
// Fireballs on Explode trigger this, sadly we can't get the blocks it would destroy... thats onEntityExplode
|
||||
// However can't figure out a way to check in onEntityExplode if it was a Fireball which caused it...
|
||||
//}
|
||||
//}
|
||||
|
||||
public void onEntityDamage(EntityDamageEvent event){
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
Entity attacker = null;
|
||||
|
||||
// public void onExplosionPrimed(ExplosionPrimedEvent event){
|
||||
// if(event.getEntity() instanceof Fireball){
|
||||
// MultiVerseCore.log.info();
|
||||
// Fireballs on Explode trigger this, sadly we can't get the blocks it would destroy... thats onEntityExplode
|
||||
// However can't figure out a way to check in onEntityExplode if it was a Fireball which caused it...
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
Entity attacker = null;
|
||||
Entity defender = event.getEntity();
|
||||
World w = defender.getWorld();
|
||||
|
||||
if(!(MultiVerseCore.configWorlds.getBoolean("worlds." + w.getName() + ".enablehealth", true))){
|
||||
|
||||
if (!(MultiVerseCore.configWorlds.getBoolean("worlds." + w.getName() + ".enablehealth", true))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(event instanceof EntityDamageByEntityEvent){
|
||||
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
attacker = ((EntityDamageByEntityEvent) event).getDamager();
|
||||
} else if(event instanceof EntityDamageByProjectileEvent){
|
||||
} else if (event instanceof EntityDamageByProjectileEvent) {
|
||||
attacker = ((EntityDamageByProjectileEvent) event).getDamager();
|
||||
}
|
||||
|
||||
if(attacker==null || defender==null){
|
||||
|
||||
if (attacker == null || defender == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (defender instanceof Player && attacker instanceof Player){
|
||||
|
||||
if (defender instanceof Player && attacker instanceof Player) {
|
||||
Player player = (Player) attacker;
|
||||
if (!(this.plugin.worlds.get(w.getName()).pvp)) {
|
||||
this.plugin.getPlayerSession(player).message(ChatColor.RED + "PVP is disabled in this World.");
|
||||
@ -73,30 +77,33 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit.
|
||||
*/
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event){
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
if(event.isCancelled()) return;
|
||||
if(!(plugin.worlds.containsKey(world.getName()))) return; // Check if it's a world which we are meant to be managing.
|
||||
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (!(plugin.worlds.containsKey(world.getName())))
|
||||
return; // Check if it's a world which we are meant to be managing.
|
||||
|
||||
CreatureType creature = event.getCreatureType();
|
||||
|
||||
//event.getEntity().getWorld().spawnCreature(arg0, arg1);
|
||||
|
||||
|
||||
// event.getEntity().getWorld().spawnCreature(arg0, arg1);
|
||||
|
||||
MVWorld mvworld = plugin.worlds.get(world.getName());
|
||||
|
||||
// TODO: Look of this and see if there's a cleaner/better method of doing so...
|
||||
|
||||
|
||||
/**
|
||||
* Animal Handling
|
||||
*/
|
||||
if(event.getEntity() instanceof Animals){
|
||||
if (event.getEntity() instanceof Animals) {
|
||||
// If we have no exceptions for Animals then we just follow the Spawn setting.
|
||||
if(mvworld.animalList.size()<=0){
|
||||
if(mvworld.animals){
|
||||
if (mvworld.animalList.size() <= 0) {
|
||||
if (mvworld.animals) {
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
@ -104,8 +111,8 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
|
||||
if(mvworld.animalList.contains(creature.toString())){
|
||||
if(mvworld.animals){
|
||||
if (mvworld.animalList.contains(creature.toString())) {
|
||||
if (mvworld.animals) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
@ -116,10 +123,10 @@ public class MVEntityListener extends EntityListener {
|
||||
/**
|
||||
* Monster Handling
|
||||
*/
|
||||
if(event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof PigZombie || event.getEntity() instanceof Slime){
|
||||
if (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof PigZombie || event.getEntity() instanceof Slime) {
|
||||
// If we have no exceptions for Monsters then we just follow the Spawn setting.
|
||||
if(mvworld.monsterList.size()<=0){
|
||||
if(mvworld.monsters){
|
||||
if (mvworld.monsterList.size() <= 0) {
|
||||
if (mvworld.monsters) {
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
@ -127,8 +134,8 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
|
||||
if(mvworld.monsterList.contains(creature.toString())){
|
||||
if(mvworld.monsters){
|
||||
if (mvworld.monsterList.contains(creature.toString())) {
|
||||
if (mvworld.monsters) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
@ -136,17 +143,17 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ghast Handling -- This should only be temporary, noticed a bug where Ghasts would keep spawning and flood the Nether.
|
||||
* However not sure about it... not sure of the effect on performance... got a few 'server overloaded' warnings through testing but not sure of the cause.
|
||||
*/
|
||||
if(event.getEntity() instanceof Ghast){
|
||||
if (event.getEntity() instanceof Ghast) {
|
||||
List<Entity> entities = world.getEntities();
|
||||
int count = 0;
|
||||
for(Entity entity : entities){
|
||||
if(entity instanceof Ghast){
|
||||
if(count>=MultiVerseCore.configMV.getInt("ghastlimit", 50)){
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof Ghast) {
|
||||
if (count >= MultiVerseCore.configMV.getInt("ghastlimit", 50)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -155,5 +162,5 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
|
||||
public class MVPermissions {
|
||||
|
||||
private MultiVerseCore plugin;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor FTW
|
||||
* @param plugin Pass along the Core Plugin.
|
||||
@ -24,18 +24,18 @@ public class MVPermissions {
|
||||
* @param node The permission node we are checking against.
|
||||
* @return
|
||||
*/
|
||||
public boolean has(Player p, String node){
|
||||
public boolean has(Player p, String node) {
|
||||
boolean result = false;
|
||||
|
||||
if(MultiVerseCore.Permissions!=null){
|
||||
|
||||
if (MultiVerseCore.Permissions != null) {
|
||||
result = MultiVerseCore.Permissions.has(p, node);
|
||||
} else if(p.isOp()){
|
||||
} else if (p.isOp()) {
|
||||
result = true;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Player can teleport to the Destination world from there
|
||||
* current world. This checks against the Worlds Blacklist
|
||||
@ -62,7 +62,7 @@ public class MVPermissions {
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the Player has the permissions to enter this world.
|
||||
* @param p
|
||||
@ -72,13 +72,13 @@ public class MVPermissions {
|
||||
public Boolean canEnterWorld(Player p, World w) {
|
||||
String group = "";
|
||||
|
||||
if (MultiVerseCore.Permissions!=null){
|
||||
group = MultiVerseCore.Permissions.getGroup(p.getName(),p.getWorld().getName());
|
||||
if (MultiVerseCore.Permissions != null) {
|
||||
group = MultiVerseCore.Permissions.getGroup(p.getName(), p.getWorld().getName());
|
||||
}
|
||||
|
||||
|
||||
List<String> whiteList = this.plugin.worlds.get(w.getName()).joinWhitelist;
|
||||
List<String> blackList = this.plugin.worlds.get(w.getName()).joinBlacklist;
|
||||
|
||||
|
||||
boolean returnValue = true;
|
||||
|
||||
// TODO: Not sure if I want this.
|
||||
@ -86,34 +86,34 @@ public class MVPermissions {
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < whiteList.size(); i++){
|
||||
for (int i = 0; i < whiteList.size(); i++) {
|
||||
if (whiteList.get(i).contains("g:") && group.equalsIgnoreCase(whiteList.get(i).split(":")[1])) {
|
||||
returnValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < blackList.size(); i++){
|
||||
for (int i = 0; i < blackList.size(); i++) {
|
||||
if (blackList.get(i).contains("g:") && group.equalsIgnoreCase(blackList.get(i).split(":")[1])) {
|
||||
returnValue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < whiteList.size(); i++){
|
||||
for (int i = 0; i < whiteList.size(); i++) {
|
||||
if (whiteList.get(i).equalsIgnoreCase(p.getName())) {
|
||||
returnValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < blackList.size(); i++){
|
||||
for (int i = 0; i < blackList.size(); i++) {
|
||||
if (blackList.get(i).equalsIgnoreCase(p.getName())) {
|
||||
returnValue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
@ -11,20 +11,21 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
public class MVPlayerListener extends PlayerListener {
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
|
||||
public MVPlayerListener(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void onPlayerTeleport(PlayerMoveEvent event){
|
||||
//MultiVerseCore.debugMsg(event.getPlayer().getName() + " just tried to Teleport");
|
||||
//event.setCancelled(true);
|
||||
public void onPlayerTeleport(PlayerMoveEvent event) {
|
||||
// MultiVerseCore.debugMsg(event.getPlayer().getName() + " just tried to Teleport");
|
||||
// event.setCancelled(true);
|
||||
// Entity entity = event.getPlayer().;
|
||||
//MultiVerseCore.log.info("1 - " + event.getTo().toString());
|
||||
//MultiVerseCore.log.info("2 - " + event.getPlayer().getLocation().toString());
|
||||
// MultiVerseCore.log.info("1 - " + event.getTo().toString());
|
||||
// MultiVerseCore.log.info("2 - " + event.getPlayer().getLocation().toString());
|
||||
}
|
||||
|
||||
public void onPlayerMove(PlayerMoveEvent event){
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player p = event.getPlayer(); // Grab Player
|
||||
Location loc = p.getLocation(); // Grab Location
|
||||
/**
|
||||
@ -32,26 +33,28 @@ public class MVPlayerListener extends PlayerListener {
|
||||
* This is to prevent huge performance drops on high player count servers.
|
||||
*/
|
||||
MVPlayerSession ps = this.plugin.getPlayerSession(p);
|
||||
if(ps.loc.getBlockX()==loc.getBlockX() && ps.loc.getBlockY()==loc.getBlockY() && ps.loc.getBlockZ()==loc.getBlockZ()) {
|
||||
if (ps.loc.getBlockX() == loc.getBlockX() && ps.loc.getBlockY() == loc.getBlockY() && ps.loc.getBlockZ() == loc.getBlockZ()) {
|
||||
return;
|
||||
} else {
|
||||
ps.loc = loc; // Update the Players Session to the new Location.
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerChat(PlayerChatEvent event){
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event){
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void onPlayerJoin(PlayerEvent event){
|
||||
|
||||
|
||||
public void onPlayerJoin(PlayerEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void onPlayerQuit(PlayerEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void onPlayerQuit(PlayerEvent event){
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,36 +9,36 @@ import org.bukkit.util.config.Configuration;
|
||||
public class MVPlayerSession {
|
||||
|
||||
private Player player; // Player holder, may be unnecessary.
|
||||
public Location loc = new Location(null, 0,0,0); // Contain the Players Location so on player move we can compare this and check if they've moved a block.
|
||||
|
||||
public Location loc = new Location(null, 0, 0, 0); // Contain the Players Location so on player move we can compare this and check if they've moved a block.
|
||||
|
||||
public String portal = null; // Allow a player to target a portal to prevent them typing its name every command.
|
||||
|
||||
|
||||
public Location coord1 = null; // Coordinate 1 (Left Click)
|
||||
public Location coord2 = null; // Coordinate 2 (Right Click)
|
||||
|
||||
|
||||
private Long teleportLast = 0L; // Timestamp for the Players last Portal Teleportation.
|
||||
private Long messageLast = 0L; // Timestamp for the Players last Alert Message.
|
||||
|
||||
|
||||
private Configuration config; // Configuration file to find out Cooldown Timers.
|
||||
|
||||
|
||||
public MVPlayerSession(Player player, Configuration config, MultiVerseCore multiVerseCore) {
|
||||
this.player = player;
|
||||
this.loc = player.getLocation();
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the Teleport time.
|
||||
*/
|
||||
public void teleport(){
|
||||
public void teleport() {
|
||||
this.teleportLast = (new Date()).getTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab whether the cooldown on Portal use has expired or not.
|
||||
* @return
|
||||
*/
|
||||
public boolean getTeleportable(){
|
||||
public boolean getTeleportable() {
|
||||
Long time = (new Date()).getTime();
|
||||
if ((time - this.teleportLast) > config.getInt("portalcooldown", 5000)) {
|
||||
return true;
|
||||
@ -46,14 +46,14 @@ public class MVPlayerSession {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a Message to the Player as long as enough time has passed since the last message.
|
||||
* @param msg
|
||||
*/
|
||||
public void message(String msg){
|
||||
public void message(String msg) {
|
||||
Long time = (new Date()).getTime();
|
||||
if((time - this.messageLast) > config.getInt("messagecooldown", 2000)){
|
||||
if ((time - this.messageLast) > config.getInt("messagecooldown", 2000)) {
|
||||
this.player.sendMessage(msg);
|
||||
this.messageLast = time;
|
||||
}
|
||||
|
@ -10,58 +10,58 @@ import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
public class MVPluginListener extends ServerListener {
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
|
||||
public MVPluginListener(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Keep an eye out for Plugins which we can utilize.
|
||||
*/
|
||||
public void onPluginEnabled(PluginEvent event){
|
||||
|
||||
public void onPluginEnabled(PluginEvent event) {
|
||||
|
||||
/**
|
||||
* Check to see if Permissions was just enabled, we only wan't to perform the following if GroupManager is not found.
|
||||
*/
|
||||
if(event.getPlugin().getDescription().getName().equals("Permissions")) {
|
||||
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
|
||||
MultiVerseCore.Permissions = ((Permissions) plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler();
|
||||
MultiVerseCore.log.info(MultiVerseCore.logPrefix + "- Found Permissions");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use the METHOD supplied by iConomy to register it etc...
|
||||
*/
|
||||
if(MultiVerseCore.getiConomy() == null) {
|
||||
if (MultiVerseCore.getiConomy() == null) {
|
||||
Plugin iConomy = plugin.getServer().getPluginManager().getPlugin("iConomy");
|
||||
|
||||
if (iConomy != null) {
|
||||
if(iConomy.isEnabled()) {
|
||||
if (iConomy.isEnabled()) {
|
||||
MultiVerseCore.iConomy = (iConomy) iConomy;
|
||||
MultiVerseCore.log.info(MultiVerseCore.logPrefix + "- Found iConomy");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We'll check if any of the plugins we rely on decide to Disable themselves.
|
||||
*/
|
||||
public void onPluginDisabled(PluginEvent event){
|
||||
public void onPluginDisabled(PluginEvent event) {
|
||||
/**
|
||||
* Check to see if Permissions just disabled.
|
||||
*/
|
||||
if(event.getPlugin().getDescription().getName().equals("Permissions")) {
|
||||
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
|
||||
MultiVerseCore.Permissions = null;
|
||||
MultiVerseCore.log.info(MultiVerseCore.logPrefix + "- Permissions has been Disabled");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check to see if iConomy just disabled.
|
||||
*/
|
||||
if(MultiVerseCore.getiConomy() != null) {
|
||||
if (MultiVerseCore.getiConomy() != null) {
|
||||
MultiVerseCore.iConomy = null;
|
||||
MultiVerseCore.log.info(MultiVerseCore.logPrefix + "- iConom has been Disabled");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,46 +3,46 @@ package com.onarandombox.MultiVerseCore;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.onarandombox.utils.BlockSafety;
|
||||
|
||||
public class MVTeleport {
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
BlockSafety bs = new BlockSafety();
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
BlockSafety bs = new BlockSafety();
|
||||
|
||||
public MVTeleport(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Sort out JavaDoc
|
||||
* @param l
|
||||
* @param w
|
||||
* @return
|
||||
*/
|
||||
public Location getCompressedLocation(Player p, World w){
|
||||
public Location getCompressedLocation(Player p, World w) {
|
||||
Location l = p.getLocation();
|
||||
// Check if they are the same world, might as well skip any calculations.
|
||||
if(l.getWorld().getName().equalsIgnoreCase(w.getName())){
|
||||
if (l.getWorld().getName().equalsIgnoreCase(w.getName())) {
|
||||
return l;
|
||||
}
|
||||
|
||||
double x,y,z;
|
||||
|
||||
|
||||
double x, y, z;
|
||||
|
||||
// Grab the Compression value for each world.
|
||||
double srcComp = plugin.worlds.get(l.getWorld().getName()).compression;
|
||||
double trgComp = plugin.worlds.get(w.getName()).compression;
|
||||
|
||||
MultiVerseCore.debugMsg(p.getName() + " -> " + p.getWorld().getName() + "(" + srcComp + ") -> " + w.getName() + "(" + trgComp + ")");
|
||||
|
||||
|
||||
// If the Targets Compression is 0 then we teleport them to the Spawn of the World.
|
||||
if(trgComp==0.0){
|
||||
if (trgComp == 0.0) {
|
||||
x = w.getSpawnLocation().getX();
|
||||
y = w.getSpawnLocation().getY();
|
||||
z = w.getSpawnLocation().getZ();
|
||||
@ -51,75 +51,97 @@ public class MVTeleport {
|
||||
y = l.getY();
|
||||
z = l.getZ() / (srcComp != 0 ? srcComp : 1) * trgComp;
|
||||
}
|
||||
return new Location(w,x,y,z);
|
||||
return new Location(w, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function gets a safe place to teleport to.
|
||||
*
|
||||
* @param world
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public Location getSafeDestination(Location l) {
|
||||
double x = l.getX();
|
||||
double y = l.getY();
|
||||
double z = l.getZ();
|
||||
|
||||
/**
|
||||
* This function gets a safe place to teleport to.
|
||||
*
|
||||
* @param world
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public Location getSafeDestination(Location l) {
|
||||
double x = l.getX();
|
||||
double y = l.getY();
|
||||
double z = l.getZ();
|
||||
World w = l.getWorld();
|
||||
|
||||
|
||||
// To make things easier we'll start with the Y Coordinate on top of a Solid Block.
|
||||
//while (bs.blockIsAboveAir(w, x, y, z)) {
|
||||
//y--;
|
||||
//}
|
||||
|
||||
double i = 0, r = 0, aux = -1;
|
||||
for (r = 0; r < 32; r++) {
|
||||
for (i = x - r; i <= x + r; i++) {
|
||||
if ((aux = safeColumn(w, i, y, z - r)) > -1) {z = z - r; break;}
|
||||
if ((aux = safeColumn(w, i, y, z + r)) > -1) {z = z + r; break;}
|
||||
}
|
||||
if (aux > -1) {x = i; break;}
|
||||
for (i = z - r + 1; i <= z + r - 1; i++) {
|
||||
if ((aux = safeColumn(w, x - r, y, i)) > -1) {x = x - r; break;}
|
||||
if ((aux = safeColumn(w, x + r, y, i)) > -1) {x = x + r; break;}
|
||||
}
|
||||
if (aux > -1) {z = i; break;}
|
||||
}
|
||||
|
||||
if (aux == -1) {
|
||||
MultiVerseCore.debugMsg("Uh oh, no safe location.");
|
||||
return null;
|
||||
}
|
||||
|
||||
MultiVerseCore.debugMsg("Target location (safe): " + x + ", " + aux + ", " + z);
|
||||
|
||||
return new Location(w, x, aux, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the Column given to see if there is an available safe spot.
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
private double safeColumn(World world, double x, double y, double z) {
|
||||
for (double ny=0; ny<48;ny++){
|
||||
if ((y+ny<120) && !bs.blockIsNotSafe(world, x, y+ny, z)) { return y+ny; }
|
||||
if ((y-ny>4) && !bs.blockIsNotSafe(world, x, y-ny, z)) { return y-ny; }
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a portal around the given location and return a new location.
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
public Location findPortal(Location location){
|
||||
World world = location.getWorld();
|
||||
// Get list of columns in a circle around the block
|
||||
// while (bs.blockIsAboveAir(w, x, y, z)) {
|
||||
// y--;
|
||||
// }
|
||||
|
||||
double i = 0, r = 0, aux = -1;
|
||||
for (r = 0; r < 32; r++) {
|
||||
for (i = x - r; i <= x + r; i++) {
|
||||
if ((aux = safeColumn(w, i, y, z - r)) > -1) {
|
||||
z = z - r;
|
||||
break;
|
||||
}
|
||||
if ((aux = safeColumn(w, i, y, z + r)) > -1) {
|
||||
z = z + r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aux > -1) {
|
||||
x = i;
|
||||
break;
|
||||
}
|
||||
for (i = z - r + 1; i <= z + r - 1; i++) {
|
||||
if ((aux = safeColumn(w, x - r, y, i)) > -1) {
|
||||
x = x - r;
|
||||
break;
|
||||
}
|
||||
if ((aux = safeColumn(w, x + r, y, i)) > -1) {
|
||||
x = x + r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aux > -1) {
|
||||
z = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (aux == -1) {
|
||||
MultiVerseCore.debugMsg("Uh oh, no safe location.");
|
||||
return null;
|
||||
}
|
||||
|
||||
MultiVerseCore.debugMsg("Target location (safe): " + x + ", " + aux + ", " + z);
|
||||
|
||||
return new Location(w, x, aux, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the Column given to see if there is an available safe spot.
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
private double safeColumn(World world, double x, double y, double z) {
|
||||
for (double ny = 0; ny < 48; ny++) {
|
||||
if ((y + ny < 120) && !bs.blockIsNotSafe(world, x, y + ny, z)) {
|
||||
return y + ny;
|
||||
}
|
||||
if ((y - ny > 4) && !bs.blockIsNotSafe(world, x, y - ny, z)) {
|
||||
return y - ny;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a portal around the given location and return a new location.
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
public Location findPortal(Location location) {
|
||||
World world = location.getWorld();
|
||||
// Get list of columns in a circle around the block
|
||||
ArrayList<Block> columns = new ArrayList<Block>();
|
||||
for (int x = location.getBlockX() - 8; x <= location.getBlockX() + 8; ++x) {
|
||||
for (int z = location.getBlockZ() - 8; z <= location.getBlockZ() + 8; ++z) {
|
||||
@ -135,17 +157,16 @@ public class MVTeleport {
|
||||
for (int y = 0; y <= 127; y++) {
|
||||
Block b = world.getBlockAt(col.getX(), y, col.getZ());
|
||||
if (b.getType().equals(Material.PORTAL)) {
|
||||
if (b.getWorld().getBlockAt(b.getX() + 1, b.getY(), b.getZ()).getType().equals(Material.PORTAL) ||
|
||||
b.getWorld().getBlockAt(b.getX() - 1, b.getY(), b.getZ()).getType().equals(Material.PORTAL)) {
|
||||
// portal is in X direction
|
||||
return new Location(b.getWorld(), b.getX() + 0.5,b.getY(), b.getZ() + 1.5);
|
||||
} else {
|
||||
// portal is in Z direction
|
||||
return new Location(b.getWorld(), b.getX() + 1.5,b.getY(), b.getZ() + 0.5);
|
||||
}
|
||||
if (b.getWorld().getBlockAt(b.getX() + 1, b.getY(), b.getZ()).getType().equals(Material.PORTAL) || b.getWorld().getBlockAt(b.getX() - 1, b.getY(), b.getZ()).getType().equals(Material.PORTAL)) {
|
||||
// portal is in X direction
|
||||
return new Location(b.getWorld(), b.getX() + 0.5, b.getY(), b.getZ() + 1.5);
|
||||
} else {
|
||||
// portal is in Z direction
|
||||
return new Location(b.getWorld(), b.getX() + 1.5, b.getY(), b.getZ() + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,75 +2,71 @@ package com.onarandombox.MultiVerseCore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
import com.onarandombox.utils.LocationManipulation;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class MVWorld {
|
||||
|
||||
private MultiVerseCore plugin; // Hold the Plugin Instance.
|
||||
private Configuration config; // Hold the Configuration File.
|
||||
|
||||
|
||||
public World world; // The World Instance.
|
||||
public Environment environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL
|
||||
|
||||
public String name; // The Worlds Name, EG its folder name.
|
||||
public String alias = ""; // Short Alias for the World, this will be used in Chat Prefixes.
|
||||
|
||||
|
||||
public Boolean animals; // Does this World allow Animals to Spawn?
|
||||
public List<String> animalList = new ArrayList<String>(); // Contain a list of Animals which we want to ignore the Spawn Setting.
|
||||
|
||||
|
||||
public Boolean monsters; // Does this World allow Monsters to Spawn?
|
||||
public List<String> monsterList = new ArrayList<String>(); // Contain a list of Monsters which we want to ignore the Spawn Setting.
|
||||
|
||||
public Boolean pvp; // Does this World allow PVP?
|
||||
|
||||
|
||||
public List<String> blockBlacklist; // Contain a list of Blocks which we won't allow on this World.
|
||||
public List<String> joinWhitelist; // Contain a list of Players/Groups which can join this World.
|
||||
public List<String> joinBlacklist; // Contain a list of Players/Groups which cannot join this World.
|
||||
public List<String> editWhitelist; // Contain a list of Players/Groups which can edit this World. (Place/Destroy Blocks)
|
||||
public List<String> editBlacklist; // Contain a list of Players/Groups which cannot edit this World. (Place/Destroy Blocks)
|
||||
public List<String> worldBlacklist; // Contain a list of Worlds which Players cannot use to Portal to this World.
|
||||
|
||||
public Double compression; //How stretched/compressed distances are
|
||||
|
||||
public MVWorld(World world, Configuration config, MultiVerseCore instance){
|
||||
public Double compression; // How stretched/compressed distances are
|
||||
|
||||
public MVWorld(World world, Configuration config, MultiVerseCore instance) {
|
||||
this.config = config;
|
||||
this.plugin = instance;
|
||||
|
||||
|
||||
this.world = world;
|
||||
this.name = world.getName();
|
||||
this.environment = world.getEnvironment();
|
||||
|
||||
this.alias = config.getString("worlds." + this.name + ".alias","");
|
||||
|
||||
this.alias = config.getString("worlds." + this.name + ".alias", "");
|
||||
this.pvp = config.getBoolean("worlds." + this.name + ".pvp", true);
|
||||
|
||||
|
||||
this.compression = config.getDouble("worlds." + this.name + ".compression", 1.0);
|
||||
|
||||
|
||||
this.joinWhitelist = config.getStringList("worlds." + name + ".playerWhitelist", new ArrayList<String>());
|
||||
this.joinBlacklist = config.getStringList("worlds." + name + ".playerBlacklist", new ArrayList<String>());
|
||||
this.worldBlacklist = config.getStringList("worlds." + name + ".worldBlacklist", new ArrayList<String>());
|
||||
this.blockBlacklist = config.getStringList("worlds." + name + ".blockBlacklist", new ArrayList<String>());
|
||||
this.editWhitelist = config.getStringList("worlds." + name + ".editWhitelist", new ArrayList<String>());
|
||||
this.editBlacklist = config.getStringList("worlds." + name + ".editBlacklist", new ArrayList<String>());
|
||||
|
||||
|
||||
this.animals = config.getBoolean("worlds." + name + ".animals.spawn", true);
|
||||
this.monsters = config.getBoolean("worlds." + name + ".monsters.spawn", true);
|
||||
|
||||
|
||||
List<String> temp;
|
||||
temp = config.getStringList("worlds." + name + ".animals.exceptions", new ArrayList<String>());
|
||||
for(String s : temp){
|
||||
for (String s : temp) {
|
||||
this.animalList.add(s.toUpperCase());
|
||||
}
|
||||
temp = config.getStringList("worlds." + name + ".monsters.exceptions", new ArrayList<String>());
|
||||
for(String s : temp){
|
||||
for (String s : temp) {
|
||||
this.monsterList.add(s.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,90 +14,99 @@ import org.bukkit.World.Environment;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
|
||||
import com.nijiko.coelho.iConomy.iConomy;
|
||||
|
||||
import com.onarandombox.MultiVerseCore.commands.*;
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVCoord;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVCreate;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVImport;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVList;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVModify;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVReload;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVRemove;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVSetSpawn;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVSpawn;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVTP;
|
||||
import com.onarandombox.MultiVerseCore.commands.MVWho;
|
||||
import com.onarandombox.MultiVerseCore.configuration.DefaultConfiguration;
|
||||
import com.onarandombox.utils.UpdateChecker;
|
||||
|
||||
public class MultiVerseCore extends JavaPlugin {
|
||||
|
||||
|
||||
// Setup our Map for our Commands using the CommandHandler.
|
||||
private Map<String, MVCommandHandler> commands = new HashMap<String, MVCommandHandler>();
|
||||
|
||||
|
||||
// Variable to state whether we are displaying Debug Messages or not.
|
||||
public static boolean debug = true;
|
||||
|
||||
|
||||
// Useless stuff to keep us going.
|
||||
public static final Logger log = Logger.getLogger("Minecraft");
|
||||
public static final String logPrefix = "[MultiVerse-Core] ";
|
||||
public static Plugin instance;
|
||||
public static Server server;
|
||||
public static PluginDescriptionFile description;
|
||||
|
||||
|
||||
// Setup a variable to hold our DataFolder which will house everything to do with MultiVerse
|
||||
// Using this instead of getDataFolder(), allows all modules to use the same direectory.
|
||||
public static final File dataFolder = new File("plugins" + File.separator + "MultiVerse");
|
||||
|
||||
|
||||
// MultiVerse Permissions Handler
|
||||
public MVPermissions ph = new MVPermissions(this);
|
||||
|
||||
|
||||
// Permissions Handler
|
||||
public static PermissionHandler Permissions = null;
|
||||
|
||||
|
||||
// iConomy Handler
|
||||
public static iConomy iConomy = null;
|
||||
public static boolean useiConomy = false;
|
||||
|
||||
|
||||
// Configurations
|
||||
public static Configuration configMV = null;
|
||||
public static Configuration configWorlds = null;
|
||||
|
||||
|
||||
// Setup the block/player/entity listener.
|
||||
private MVPlayerListener playerListener = new MVPlayerListener(this);;
|
||||
private MVBlockListener blockListener = new MVBlockListener(this);
|
||||
private MVEntityListener entityListener = new MVEntityListener(this);
|
||||
private MVPluginListener pluginListener = new MVPluginListener(this);
|
||||
|
||||
|
||||
public UpdateChecker updateCheck;
|
||||
|
||||
|
||||
// HashMap to contain all the Worlds which this Plugin will manage.
|
||||
public HashMap<String,MVWorld> worlds = new HashMap<String,MVWorld>();
|
||||
|
||||
public HashMap<String, MVWorld> worlds = new HashMap<String, MVWorld>();
|
||||
|
||||
// HashMap to contain information relating to the Players.
|
||||
public HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor... Perform the Necessary tasks here.
|
||||
*/
|
||||
public MultiVerseCore(){
|
||||
|
||||
public MultiVerseCore() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* What happens when the plugin gets around to being enabled...
|
||||
*/
|
||||
|
||||
/**
|
||||
* What happens when the plugin gets around to being enabled...
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Create the Plugin Data folder.
|
||||
dataFolder.mkdir();
|
||||
|
||||
// Output a little snippet to show it's enabled.
|
||||
log.info(logPrefix + "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
|
||||
|
||||
|
||||
// Setup & Load our Configuration files.
|
||||
loadConfigs();
|
||||
|
||||
|
||||
// Setup all the Events the plugin needs to Monitor.
|
||||
registerEvents();
|
||||
// Call the Function to load all the Worlds and setup the HashMap
|
||||
@ -110,34 +119,34 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
setupiConomy();
|
||||
// Call the Function to assign all the Commands to their Class.
|
||||
setupCommands();
|
||||
|
||||
|
||||
// Start the Update Checker
|
||||
updateCheck = new UpdateChecker(this.getDescription().getName(),this.getDescription().getVersion());
|
||||
updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to Register all the Events needed.
|
||||
*/
|
||||
private void registerEvents(){
|
||||
private void registerEvents() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Highest, this); // Low so it acts above any other.
|
||||
pm.registerEvent(Event.Type.PLAYER_TELEPORT, playerListener, Priority.Highest, this); // Cancel Teleports if needed.
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener,Priority.Normal, this); // To remove Player Sessions
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); // To remove Player Sessions
|
||||
|
||||
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); // To prevent Blocks being destroyed.
|
||||
//pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); // To prevent Blocks being placed.
|
||||
|
||||
//pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth.
|
||||
|
||||
// pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this); // To prevent Blocks being placed.
|
||||
|
||||
// pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Normal, this); // To Allow/Disallow PVP as well as EnableHealth.
|
||||
|
||||
pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this); // To prevent all or certain animals/monsters from spawning.
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
|
||||
//pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
|
||||
|
||||
// pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
|
||||
|
||||
pm.registerEvent(Event.Type.PLUGIN_ENABLE, pluginListener, Priority.Monitor, this); // Monitor for Permissions Plugin etc.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for Permissions plugin and then setup our own Permissions Handler.
|
||||
*/
|
||||
@ -146,12 +155,12 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
|
||||
if (MultiVerseCore.Permissions == null) {
|
||||
if (p != null && p.isEnabled()) {
|
||||
MultiVerseCore.Permissions = ((Permissions)p).getHandler();
|
||||
MultiVerseCore.Permissions = ((Permissions) p).getHandler();
|
||||
MultiVerseCore.log.info(logPrefix + "- Attached to Permissions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for the iConomy plugin and set it up accordingly.
|
||||
*/
|
||||
@ -164,7 +173,7 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Configuration files OR create the default config files.
|
||||
*/
|
||||
@ -172,22 +181,26 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
// Call the defaultConfiguration class to create the config files if they don't already exist.
|
||||
new DefaultConfiguration(dataFolder, "config.yml");
|
||||
new DefaultConfiguration(dataFolder, "worlds.yml", "worlds:");
|
||||
|
||||
|
||||
// Now grab the Configuration Files.
|
||||
configMV = new Configuration(new File(dataFolder, "config.yml"));
|
||||
configWorlds = new Configuration(new File(dataFolder, "worlds.yml"));
|
||||
|
||||
|
||||
// Now attempt to Load the configurations.
|
||||
try{
|
||||
try {
|
||||
configMV.load();
|
||||
log.info(logPrefix + "- MultiVerse Config -- Loaded");
|
||||
} catch (Exception e){ log.info(MultiVerseCore.logPrefix + "- Failed to load config.yml"); }
|
||||
|
||||
try{
|
||||
} catch (Exception e) {
|
||||
log.info(MultiVerseCore.logPrefix + "- Failed to load config.yml");
|
||||
}
|
||||
|
||||
try {
|
||||
configWorlds.load();
|
||||
log.info(logPrefix + "- World Config -- Loaded");
|
||||
} catch (Exception e){ log.info(MultiVerseCore.logPrefix + "- Failed to load worlds.yml"); }
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info(MultiVerseCore.logPrefix + "- Failed to load worlds.yml");
|
||||
}
|
||||
|
||||
// Setup the Debug option, we'll default to false because this option will not be in the default config.
|
||||
MultiVerseCore.debug = configMV.getBoolean("debug", false);
|
||||
}
|
||||
@ -196,21 +209,25 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
* Purge the Worlds of Entities that are disallowed.
|
||||
*/
|
||||
private void purgeWorlds() {
|
||||
if(worlds.size()<=0) return;
|
||||
if (worlds.size() <= 0)
|
||||
return;
|
||||
|
||||
Set<String> worldKeys = worlds.keySet();
|
||||
for (String key : worldKeys){
|
||||
for (String key : worldKeys) {
|
||||
World world = getServer().getWorld(key);
|
||||
if(world==null) continue;
|
||||
|
||||
if (world == null)
|
||||
continue;
|
||||
|
||||
// TODO: Sort out the Entity Purge, only purge what is configured to be.
|
||||
|
||||
/*List<LivingEntity> entities = world.getLivingEntities();
|
||||
|
||||
MVWorld mvworld = worlds.get(key);
|
||||
for (Entity entity: entities){
|
||||
|
||||
}*/
|
||||
/*
|
||||
* List<LivingEntity> entities = world.getLivingEntities();
|
||||
*
|
||||
* MVWorld mvworld = worlds.get(key);
|
||||
* for (Entity entity: entities){
|
||||
*
|
||||
* }
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,80 +247,81 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
commands.put("mvwho", new MVWho(this));
|
||||
commands.put("mvreload", new MVReload(this));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Worlds & Settings from the configuration file.
|
||||
*/
|
||||
public void loadWorlds() {
|
||||
// Basic Counter to count how many Worlds we are loading.
|
||||
int count = 0;
|
||||
List<String> worldKeys = MultiVerseCore.configWorlds.getKeys("worlds"); // Grab all the Worlds from the Config.
|
||||
|
||||
if(worldKeys != null){
|
||||
for (String worldKey : worldKeys){
|
||||
// If this World already exists within the HashMap then we don't need to process it.
|
||||
if(worlds.containsKey(worldKey)){
|
||||
continue;
|
||||
}
|
||||
|
||||
String wEnvironment = MultiVerseCore.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
|
||||
|
||||
Environment env;
|
||||
if(wEnvironment.equalsIgnoreCase("NETHER")) // Check if the selected Environment is NETHER, otherwise we just default to NORMAL.
|
||||
env = Environment.NETHER;
|
||||
else
|
||||
env = Environment.NORMAL;
|
||||
|
||||
log.info(logPrefix + "Loading World & Settings - '" + worldKey + "' - " + wEnvironment); // Output to the Log that wea re loading a world, specify the name and environment type.
|
||||
|
||||
World world = getServer().createWorld(worldKey, env);
|
||||
|
||||
worlds.put(worldKey, new MVWorld(world, MultiVerseCore.configWorlds, this)); // Place the World into the HashMap.
|
||||
|
||||
public void loadWorlds() {
|
||||
// Basic Counter to count how many Worlds we are loading.
|
||||
int count = 0;
|
||||
List<String> worldKeys = MultiVerseCore.configWorlds.getKeys("worlds"); // Grab all the Worlds from the Config.
|
||||
|
||||
if (worldKeys != null) {
|
||||
for (String worldKey : worldKeys) {
|
||||
// If this World already exists within the HashMap then we don't need to process it.
|
||||
if (worlds.containsKey(worldKey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String wEnvironment = MultiVerseCore.configWorlds.getString("worlds." + worldKey + ".environment", "NORMAL"); // Grab the Environment as a String.
|
||||
|
||||
Environment env;
|
||||
if (wEnvironment.equalsIgnoreCase("NETHER")) // Check if the selected Environment is NETHER, otherwise we just default to NORMAL.
|
||||
env = Environment.NETHER;
|
||||
else
|
||||
env = Environment.NORMAL;
|
||||
|
||||
log.info(logPrefix + "Loading World & Settings - '" + worldKey + "' - " + wEnvironment); // Output to the Log that wea re loading a world, specify the name and environment type.
|
||||
|
||||
World world = getServer().createWorld(worldKey, env);
|
||||
|
||||
worlds.put(worldKey, new MVWorld(world, MultiVerseCore.configWorlds, this)); // Place the World into the HashMap.
|
||||
|
||||
count++; // Increment the World Count.
|
||||
}
|
||||
}
|
||||
log.info(logPrefix + count + " - World(s) loaded.");
|
||||
}
|
||||
}
|
||||
log.info(logPrefix + count + " - World(s) loaded.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* What happens when the plugin gets disabled...
|
||||
*/
|
||||
public void onDisable() {
|
||||
MultiVerseCore.Permissions = null;
|
||||
log.info(logPrefix + "- Disabled");
|
||||
}
|
||||
|
||||
* What happens when the plugin gets disabled...
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
MultiVerseCore.Permissions = null;
|
||||
log.info(logPrefix + "- Disabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the players session if one exists, otherwise create a session then return it.
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public MVPlayerSession getPlayerSession(Player player){
|
||||
if(playerSessions.containsKey(player.getName())){
|
||||
public MVPlayerSession getPlayerSession(Player player) {
|
||||
if (playerSessions.containsKey(player.getName())) {
|
||||
return playerSessions.get(player.getName());
|
||||
} else {
|
||||
playerSessions.put(player.getName(), new MVPlayerSession(player, MultiVerseCore.configMV, this));
|
||||
return playerSessions.get(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab and return the Teleport class.
|
||||
* @return
|
||||
*/
|
||||
public MVTeleport getTeleporter() {
|
||||
return new MVTeleport(this);
|
||||
return new MVTeleport(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab the iConomy setup.
|
||||
* Grab the iConomy setup.
|
||||
* @return
|
||||
*/
|
||||
public static iConomy getiConomy() {
|
||||
return iConomy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Grab the Permissions Handler for MultiVerse
|
||||
*/
|
||||
@ -314,56 +332,59 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
/**
|
||||
* This fires before plugins get Enabled... Not needed but saves Console Spam.
|
||||
*/
|
||||
@Override
|
||||
public void onLoad() {
|
||||
}
|
||||
|
||||
/**
|
||||
* onCommand
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
if(this.isEnabled() == false){
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* onCommand
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
if (this.isEnabled() == false) {
|
||||
sender.sendMessage("This plugin is Disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
MVCommandHandler handler = commands.get(command.getName().toLowerCase());
|
||||
|
||||
if (handler!=null) {
|
||||
|
||||
if (handler != null) {
|
||||
return handler.perform(sender, args);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Debug Output function, if we've enabled debugging we'll output more information.
|
||||
*/
|
||||
public static void debugMsg(String msg){
|
||||
debugMsg(msg,null);
|
||||
}
|
||||
public static void debugMsg(String msg, Player p){
|
||||
if(debug){
|
||||
log.info(msg);
|
||||
if(p!=null){
|
||||
p.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Basic Debug Output function, if we've enabled debugging we'll output more information.
|
||||
*/
|
||||
public static void debugMsg(String msg) {
|
||||
debugMsg(msg, null);
|
||||
}
|
||||
|
||||
public static void debugMsg(String msg, Player p) {
|
||||
if (debug) {
|
||||
log.info(msg);
|
||||
if (p != null) {
|
||||
p.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the Authors Array into a readable String with ',' and 'and'.
|
||||
* @return
|
||||
*/
|
||||
private String getAuthors(){
|
||||
private String getAuthors() {
|
||||
String authors = "";
|
||||
ArrayList<String> auths = this.getDescription().getAuthors();
|
||||
|
||||
if(auths.size()==1){
|
||||
|
||||
if (auths.size() == 1) {
|
||||
return auths.get(0);
|
||||
}
|
||||
|
||||
for(int i=0;i<auths.size();i++){
|
||||
if(i==this.getDescription().getAuthors().size()-1){
|
||||
|
||||
for (int i = 0; i < auths.size(); i++) {
|
||||
if (i == this.getDescription().getAuthors().size() - 1) {
|
||||
authors += " and " + this.getDescription().getAuthors().get(i);
|
||||
} else {
|
||||
authors += ", " + this.getDescription().getAuthors().get(i);
|
||||
@ -371,4 +392,4 @@ public class MultiVerseCore extends JavaPlugin {
|
||||
}
|
||||
return authors.substring(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import com.onarandombox.utils.LocationManipulation;
|
||||
public class MVCoord extends MVCommandHandler {
|
||||
|
||||
private LocationManipulation locMan = new LocationManipulation();
|
||||
|
||||
|
||||
public MVCoord(MultiVerseCore plugin) {
|
||||
super(plugin);
|
||||
// TODO Auto-generated constructor stub
|
||||
@ -21,14 +21,14 @@ public class MVCoord extends MVCommandHandler {
|
||||
@Override
|
||||
public boolean perform(CommandSender sender, String[] args) {
|
||||
// Check if the command was sent from a Player.
|
||||
if(sender instanceof Player){
|
||||
if (sender instanceof Player) {
|
||||
// If this command was sent from a Player then we need to check Permissions
|
||||
if(!(plugin.ph.has(((Player) sender), "multiverse.coord"))){
|
||||
if (!(plugin.ph.has(((Player) sender), "multiverse.coord"))) {
|
||||
sender.sendMessage("You do not have access to this command.");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
|
||||
|
||||
p.sendMessage(ChatColor.RED + "World: " + ChatColor.WHITE + p.getWorld().getName());
|
||||
p.sendMessage(ChatColor.RED + "Compression: " + ChatColor.WHITE + plugin.worlds.get(p.getWorld().getName()).compression);
|
||||
p.sendMessage(ChatColor.RED + "Coordinates: " + ChatColor.WHITE + locMan.strCoords(p.getLocation()));
|
||||
|
@ -29,7 +29,7 @@ public class MVCreate extends MVCommandHandler {
|
||||
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
|
||||
return true;
|
||||
}
|
||||
//String name = args[0].toString();
|
||||
// String name = args[0].toString();
|
||||
String env = args[1].toString();
|
||||
Environment environment = null;
|
||||
if (env.equalsIgnoreCase("NETHER"))
|
||||
@ -39,10 +39,8 @@ public class MVCreate extends MVCommandHandler {
|
||||
environment = Environment.NORMAL;
|
||||
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED
|
||||
+ "Environment type does not exist!");
|
||||
sender.sendMessage(ChatColor.RED
|
||||
+ "Only Normal & Nether exist as Environments");
|
||||
sender.sendMessage(ChatColor.RED + "Environment type does not exist!");
|
||||
sender.sendMessage(ChatColor.RED + "Only Normal & Nether exist as Environments");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
@ -18,34 +18,38 @@ public class MVList extends MVCommandHandler {
|
||||
@Override
|
||||
public boolean perform(CommandSender sender, String[] args) {
|
||||
Player p = null;
|
||||
if(sender instanceof Player){
|
||||
if (sender instanceof Player) {
|
||||
p = (Player) sender;
|
||||
if(!(plugin.ph.has(p, "multiverse.world.list"))){
|
||||
if (!(plugin.ph.has(p, "multiverse.world.list"))) {
|
||||
sender.sendMessage("You do not have access to this command.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String output = ChatColor.GREEN + "Worlds which you can view - \n";
|
||||
for(int i=0;i<plugin.getServer().getWorlds().size();i++){
|
||||
for (int i = 0; i < plugin.getServer().getWorlds().size(); i++) {
|
||||
|
||||
World world = plugin.getServer().getWorlds().get(i);
|
||||
|
||||
if(!(plugin.worlds.containsKey(world.getName()))){ continue; }
|
||||
if(p!=null && (!plugin.ph.canEnterWorld(p, world))){ continue; }
|
||||
|
||||
if (!(plugin.worlds.containsKey(world.getName()))) {
|
||||
continue;
|
||||
}
|
||||
if (p != null && (!plugin.ph.canEnterWorld(p, world))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ChatColor color;
|
||||
|
||||
|
||||
if (world.getEnvironment() == Environment.NETHER)
|
||||
color = ChatColor.RED;
|
||||
else
|
||||
color = ChatColor.GREEN;
|
||||
|
||||
output += color + world.getName() + " - " + world.getEnvironment().toString() + " \n";
|
||||
|
||||
|
||||
}
|
||||
String[] response = output.split("\n");
|
||||
for(String msg : response){
|
||||
for (String msg : response) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
|
@ -6,10 +6,9 @@ import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.onarandombox.utils.PurgeWorlds;
|
||||
|
||||
import com.onarandombox.MultiVerseCore.MVCommandHandler;
|
||||
import com.onarandombox.MultiVerseCore.MultiVerseCore;
|
||||
import com.onarandombox.utils.PurgeWorlds;
|
||||
|
||||
public class MVPurge extends MVCommandHandler {
|
||||
|
||||
@ -19,24 +18,24 @@ public class MVPurge extends MVCommandHandler {
|
||||
|
||||
@Override
|
||||
public boolean perform(CommandSender sender, String[] args) {
|
||||
if(!(args.length>0)){
|
||||
if (!(args.length > 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(sender instanceof Player)){
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("This command needs to be used from inside the game!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
List<String> creatures = new ArrayList<String>();
|
||||
|
||||
for(String creature : args[0].toUpperCase().split(",")){
|
||||
|
||||
for (String creature : args[0].toUpperCase().split(",")) {
|
||||
creatures.add(creature);
|
||||
}
|
||||
|
||||
|
||||
new PurgeWorlds(plugin).purge(sender, p.getWorld(), creatures);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,11 @@ public class MVSetSpawn extends MVCommandHandler {
|
||||
@Override
|
||||
public boolean perform(CommandSender sender, String[] args) {
|
||||
// TODO: Permissions
|
||||
if(sender instanceof Player){
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
Location l = p.getLocation();
|
||||
World w = p.getWorld();
|
||||
w.setSpawnLocation(l.getBlockX(),l.getBlockY(),l.getBlockZ());
|
||||
w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
p.sendMessage(w.getName() + " - Spawn set to X: " + l.getBlockX() + " Y: " + l.getBlockY() + " Z: " + l.getBlockZ());
|
||||
} else {
|
||||
sender.sendMessage("Must be used in game");
|
||||
|
@ -15,7 +15,7 @@ public class MVSpawn extends MVCommandHandler {
|
||||
@Override
|
||||
public boolean perform(CommandSender sender, String[] args) {
|
||||
// TODO: Permissions
|
||||
if(sender instanceof Player){
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
p.teleportTo(p.getWorld().getSpawnLocation());
|
||||
} else {
|
||||
|
@ -21,22 +21,22 @@ public class MVWho extends MVCommandHandler {
|
||||
@Override
|
||||
public boolean perform(CommandSender sender, String[] args) {
|
||||
// If this command was sent from a Player then we need to check Permissions
|
||||
if(sender instanceof Player){
|
||||
if(!(plugin.ph.has(((Player) sender), "multiverse.who"))){
|
||||
if (sender instanceof Player) {
|
||||
if (!(plugin.ph.has(((Player) sender), "multiverse.who"))) {
|
||||
sender.sendMessage("You do not have access to this command.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
List<World> worlds = new ArrayList<World>();
|
||||
|
||||
if(args.length>1){
|
||||
|
||||
if (args.length > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args.length>0){
|
||||
|
||||
if (args.length > 0) {
|
||||
World world = plugin.getServer().getWorld(args[0].toString());
|
||||
if(world!=null){
|
||||
if (world != null) {
|
||||
worlds.add(world);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "World does not exist");
|
||||
@ -45,21 +45,21 @@ public class MVWho extends MVCommandHandler {
|
||||
} else {
|
||||
worlds = plugin.getServer().getWorlds();
|
||||
}
|
||||
|
||||
for(World world : worlds){
|
||||
|
||||
for (World world : worlds) {
|
||||
ChatColor color = ChatColor.BLUE;
|
||||
if(world.getEnvironment()==Environment.NETHER){
|
||||
if (world.getEnvironment() == Environment.NETHER) {
|
||||
color = ChatColor.RED;
|
||||
} else if(world.getEnvironment()==Environment.NORMAL){
|
||||
} else if (world.getEnvironment() == Environment.NORMAL) {
|
||||
color = ChatColor.GREEN;
|
||||
}
|
||||
List<Player> players = world.getPlayers();
|
||||
|
||||
String result = "";
|
||||
if(players.size() <= 0){
|
||||
if (players.size() <= 0) {
|
||||
result = "Empty";
|
||||
} else {
|
||||
for(Player player : players){
|
||||
for (Player player : players) {
|
||||
result += player.getName() + " ";
|
||||
}
|
||||
}
|
||||
|
@ -18,27 +18,27 @@ import com.onarandombox.MultiVerseCore.MultiVerseCore;
|
||||
*/
|
||||
public class DefaultConfiguration {
|
||||
|
||||
public DefaultConfiguration(File folder, String name){
|
||||
new DefaultConfiguration(folder,name,null);
|
||||
public DefaultConfiguration(File folder, String name) {
|
||||
new DefaultConfiguration(folder, name, null);
|
||||
}
|
||||
|
||||
public DefaultConfiguration(File folder, String name, String contains){
|
||||
|
||||
public DefaultConfiguration(File folder, String name, String contains) {
|
||||
File actual = new File(folder, name);
|
||||
|
||||
|
||||
if (!actual.exists()) {
|
||||
InputStream input = this.getClass().getResourceAsStream("/defaults/" + name);
|
||||
if (input != null) {
|
||||
FileOutputStream output = null;
|
||||
|
||||
|
||||
try {
|
||||
output = new FileOutputStream(actual);
|
||||
byte[] buf = new byte[8192];
|
||||
int length = 0;
|
||||
|
||||
|
||||
while ((length = input.read(buf)) > 0) {
|
||||
output.write(buf, 0, length);
|
||||
}
|
||||
|
||||
|
||||
MultiVerseCore.log.info(MultiVerseCore.logPrefix + "Default config file written: " + name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -46,62 +46,63 @@ public class DefaultConfiguration {
|
||||
try {
|
||||
if (input != null)
|
||||
input.close();
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (output != null)
|
||||
output.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(contains==null){
|
||||
if (contains == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
boolean found = false;
|
||||
|
||||
|
||||
try {
|
||||
// Open the file that is the first
|
||||
// Open the file that is the first
|
||||
// command line parameter
|
||||
FileInputStream fstream = new FileInputStream(actual);
|
||||
// Get the object of DataInputStream
|
||||
DataInputStream in = new DataInputStream(fstream);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
String strLine;
|
||||
//Read File Line By Line
|
||||
|
||||
while ((strLine = br.readLine()) != null) {
|
||||
if(strLine.equals(contains)){
|
||||
// Read File Line By Line
|
||||
|
||||
while ((strLine = br.readLine()) != null) {
|
||||
if (strLine.equals(contains)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Close the input stream
|
||||
// Close the input stream
|
||||
in.close();
|
||||
} catch (Exception e) {//Catch exception if any
|
||||
} catch (Exception e) {// Catch exception if any
|
||||
System.err.println("Error: Could not verify the contents of " + actual.toString());
|
||||
System.err.println("Error: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!found){
|
||||
|
||||
if (!found) {
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(actual, true));
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(actual, true));
|
||||
out.newLine();
|
||||
out.write(contains);
|
||||
out.close();
|
||||
out.write(contains);
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error: Could not write default node to " + actual.toString());
|
||||
System.err.println("Error: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,10 +15,9 @@ public class BlockSafety {
|
||||
* @return
|
||||
*/
|
||||
public boolean blockIsAboveAir(World world, double x, double y, double z) {
|
||||
return (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),
|
||||
(int) Math.floor(z)).getType() == Material.AIR);
|
||||
return (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.AIR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function checks whether the block at the coordinates given is safe
|
||||
* or not by checking for Laval/Fire/Air etc.
|
||||
@ -30,26 +29,25 @@ public class BlockSafety {
|
||||
* @return
|
||||
*/
|
||||
public boolean blockIsNotSafe(World world, double x, double y, double z) {
|
||||
if (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y),(int) Math.floor(z)).getType() != Material.AIR
|
||||
|| world.getBlockAt((int) Math.floor(x),(int) Math.floor(y + 1), (int) Math.floor(z)).getType() != Material.AIR)
|
||||
if (world.getBlockAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)).getType() != Material.AIR || world.getBlockAt((int) Math.floor(x), (int) Math.floor(y + 1), (int) Math.floor(z)).getType() != Material.AIR)
|
||||
return true;
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),(int) Math.floor(z)).getType() == Material.LAVA))
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.LAVA))
|
||||
return true;
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),(int) Math.floor(z)).getType() == Material.STATIONARY_LAVA))
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.STATIONARY_LAVA))
|
||||
return true;
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1),(int) Math.floor(z)).getType() == Material.FIRE))
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y - 1), (int) Math.floor(z)).getType() == Material.FIRE))
|
||||
return true;
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y),(int) Math.floor(z)).getType() == Material.FIRE))
|
||||
|
||||
if ((world.getBlockAt((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)).getType() == Material.FIRE))
|
||||
return true;
|
||||
|
||||
|
||||
if (blockIsAboveAir(world, x, y, z))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class LocationManipulation {
|
||||
|
||||
|
||||
/**
|
||||
* Convert a Location into a Colon separated string to allow us to store it in text.
|
||||
* @param location
|
||||
@ -19,6 +19,7 @@ public class LocationManipulation {
|
||||
l.append(location.getPitch());
|
||||
return l.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a String to a Location.
|
||||
* @param world
|
||||
@ -29,7 +30,7 @@ public class LocationManipulation {
|
||||
* @param pitchStr
|
||||
* @return
|
||||
*/
|
||||
public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr){
|
||||
public Location stringToLocation(World world, String xStr, String yStr, String zStr, String yawStr, String pitchStr) {
|
||||
double x = Double.parseDouble(xStr);
|
||||
double y = Double.parseDouble(yStr);
|
||||
double z = Double.parseDouble(zStr);
|
||||
@ -38,18 +39,20 @@ public class LocationManipulation {
|
||||
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Location to XYZ Coordinates.
|
||||
* @param l
|
||||
* @return
|
||||
*/
|
||||
public String strCoords(Location l){
|
||||
public String strCoords(Location l) {
|
||||
String result = "";
|
||||
result += "X: " + l.getBlockX() + " ";
|
||||
result += "Y: " + l.getBlockY() + " ";
|
||||
result += "Z: " + l.getBlockZ() + " ";
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the NESW Direction a Location is facing.
|
||||
* @param location
|
||||
|
@ -24,43 +24,34 @@ import com.onarandombox.MultiVerseCore.MultiVerseCore;
|
||||
public class PurgeWorlds {
|
||||
|
||||
MultiVerseCore plugin;
|
||||
|
||||
public PurgeWorlds(MultiVerseCore plugin){
|
||||
|
||||
public PurgeWorlds(MultiVerseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void purge(World w, List<String> creatures){
|
||||
purge(null,w,creatures);
|
||||
|
||||
public void purge(World w, List<String> creatures) {
|
||||
purge(null, w, creatures);
|
||||
}
|
||||
|
||||
public void purge(CommandSender sender, World w, List<String> creatures){
|
||||
|
||||
List<Entity> entities = w.getEntities();
|
||||
|
||||
public void purge(CommandSender sender, World w, List<String> creatures) {
|
||||
|
||||
List<Entity> entities = w.getEntities();
|
||||
int count = 0;
|
||||
|
||||
for(Entity e: entities){
|
||||
if ((((e instanceof Creeper)) && (creatures.contains("CREEPER"))) ||
|
||||
(((e instanceof Skeleton)) && (creatures.contains("SKELETON"))) ||
|
||||
(((e instanceof Spider)) && (creatures.contains("SPIDER"))) ||
|
||||
(((e instanceof Zombie)) && (creatures.contains("ZOMBIE"))) ||
|
||||
(((e instanceof Ghast)) && (creatures.contains("GHAST"))) ||
|
||||
(((e instanceof PigZombie)) && (creatures.contains("PIGZOMBIE"))) ||
|
||||
(((e instanceof Giant)) && (creatures.contains("GIANT"))) ||
|
||||
(((e instanceof Slime)) && (creatures.contains("SLIME"))) ||
|
||||
(((e instanceof Chicken)) && (creatures.contains("CHICKEN"))) ||
|
||||
(((e instanceof Cow)) && (creatures.contains("COW"))) ||
|
||||
(((e instanceof Sheep)) && (creatures.contains("SHEEP"))) ||
|
||||
(((e instanceof Pig)) && (creatures.contains("PIG"))) ||
|
||||
(((e instanceof Squid)) && (creatures.contains("SQUID"))) ||
|
||||
creatures.contains("*")) {
|
||||
|
||||
for (Entity e : entities) {
|
||||
if ((((e instanceof Creeper)) && (creatures.contains("CREEPER"))) || (((e instanceof Skeleton)) && (creatures.contains("SKELETON"))) || (((e instanceof Spider)) && (creatures.contains("SPIDER")))
|
||||
|| (((e instanceof Zombie)) && (creatures.contains("ZOMBIE"))) || (((e instanceof Ghast)) && (creatures.contains("GHAST"))) || (((e instanceof PigZombie)) && (creatures.contains("PIGZOMBIE")))
|
||||
|| (((e instanceof Giant)) && (creatures.contains("GIANT"))) || (((e instanceof Slime)) && (creatures.contains("SLIME"))) || (((e instanceof Chicken)) && (creatures.contains("CHICKEN")))
|
||||
|| (((e instanceof Cow)) && (creatures.contains("COW"))) || (((e instanceof Sheep)) && (creatures.contains("SHEEP"))) || (((e instanceof Pig)) && (creatures.contains("PIG")))
|
||||
|| (((e instanceof Squid)) && (creatures.contains("SQUID"))) || creatures.contains("*")) {
|
||||
e.remove();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if(sender!=null){
|
||||
|
||||
if (sender != null) {
|
||||
sender.sendMessage(count + " Entities Purged from " + w.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,17 +14,16 @@ import java.util.regex.Pattern;
|
||||
public class UpdateChecker {
|
||||
|
||||
public static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
|
||||
public Timer timer = new Timer(); // Create a new Timer.
|
||||
|
||||
|
||||
private String name; // Hold the Plugins Name.
|
||||
private String cversion; // Hold the Plugins Current Version.
|
||||
|
||||
|
||||
|
||||
public UpdateChecker(String name, String version) {
|
||||
this.name = name;
|
||||
this.cversion = version;
|
||||
|
||||
|
||||
int delay = 0; // No Delay, fire the first check instantly.
|
||||
int period = 1800; // Delay 30 Minutes
|
||||
|
||||
@ -41,37 +40,37 @@ public class UpdateChecker {
|
||||
URL url = new URL("http://bukkit.onarandombox.com/multiverse/version.php?n=" + URLEncoder.encode(name, "UTF-8") + "&v=" + cversion);
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setReadTimeout(2000); // 2000 = 2 Seconds.
|
||||
|
||||
|
||||
int code = ((HttpURLConnection) conn).getResponseCode();
|
||||
|
||||
if(code!=200){
|
||||
|
||||
if (code != 200) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
String version = null;
|
||||
|
||||
|
||||
while ((line = rd.readLine()) != null) {
|
||||
if (version == null) {
|
||||
version = line;
|
||||
}
|
||||
}
|
||||
|
||||
if(version==null){
|
||||
|
||||
if (version == null) {
|
||||
rd.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String v1 = normalisedVersion(version);
|
||||
String v2 = normalisedVersion(cversion);
|
||||
|
||||
int compare = v1.compareTo(v2);
|
||||
|
||||
if(compare > 0){
|
||||
log.info("[" + name + "]" + " - Update Available (" + version + ")");
|
||||
if (compare > 0) {
|
||||
log.info("[" + name + "]" + " - Update Available (" + version + ")");
|
||||
}
|
||||
|
||||
|
||||
rd.close();
|
||||
} catch (Exception e) {
|
||||
// No need to alert the user of any error here... it's not important.
|
||||
@ -86,6 +85,7 @@ public class UpdateChecker {
|
||||
public static String normalisedVersion(String version) {
|
||||
return normalisedVersion(version, ".", 4);
|
||||
}
|
||||
|
||||
public static String normalisedVersion(String version, String sep, int maxWidth) {
|
||||
String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
Loading…
Reference in New Issue
Block a user