mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-02 16:59:56 +01:00
Put your commits in the air like you just don't care!
But seriously, working on MVPurge
This commit is contained in:
parent
7271e5cfb8
commit
3124a5c678
@ -32,8 +32,8 @@ public class MVEntityListener extends EntityListener {
|
||||
|
||||
@Override
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
if(event.getEntity() instanceof Player) {
|
||||
Player p = (Player)event.getEntity();
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player p = (Player) event.getEntity();
|
||||
p.sendMessage("You died!");
|
||||
}
|
||||
super.onEntityDeath(event);
|
||||
@ -47,8 +47,10 @@ public class MVEntityListener extends EntityListener {
|
||||
World world = event.getEntity().getWorld();
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
// Check if it's a world which we are meant to be managing.
|
||||
if (!(this.plugin.isMVWorld(world.getName())))
|
||||
return; // Check if it's a world which we are meant to be managing.
|
||||
return;
|
||||
|
||||
CreatureType creature = event.getCreatureType();
|
||||
|
||||
@ -64,7 +66,7 @@ public class MVEntityListener extends EntityListener {
|
||||
if (event.getEntity() instanceof Animals) {
|
||||
// If we have no exceptions for Animals then we just follow the Spawn setting.
|
||||
if (mvworld.getAnimalList().isEmpty()) {
|
||||
if (mvworld.hasAnimals()) {
|
||||
if (mvworld.allowAnimalSpawning()) {
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
@ -72,8 +74,8 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
|
||||
if (mvworld.getAnimalList().contains(creature.toString())) {
|
||||
if (mvworld.hasAnimals()) {
|
||||
if (mvworld.getAnimalList().contains(creature.toString().toUpperCase())) {
|
||||
if (mvworld.allowAnimalSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
@ -84,10 +86,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 Slime) {
|
||||
// If we have no exceptions for Monsters then we just follow the Spawn setting.
|
||||
if (mvworld.getMonsterList().isEmpty()) {
|
||||
if (mvworld.hasMonsters()) {
|
||||
if (mvworld.allowMonsterSpawning()) {
|
||||
return;
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
@ -95,8 +97,8 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
|
||||
if (mvworld.getMonsterList().contains(creature.toString())) {
|
||||
if (mvworld.hasMonsters()) {
|
||||
if (mvworld.getMonsterList().contains(creature.toString().toUpperCase())) {
|
||||
if (mvworld.allowMonsterSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
|
@ -342,7 +342,7 @@ public class MVWorld {
|
||||
this.config.save();
|
||||
}
|
||||
|
||||
public Boolean hasAnimals() {
|
||||
public Boolean allowAnimalSpawning() {
|
||||
return this.allowAnimals;
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ public class MVWorld {
|
||||
return this.masterList.get("animals");
|
||||
}
|
||||
|
||||
public Boolean hasMonsters() {
|
||||
public Boolean allowMonsterSpawning() {
|
||||
return this.allowMonsters;
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ public class MultiverseCore extends JavaPlugin {
|
||||
/**
|
||||
* Purge the Worlds of Entities that are disallowed.
|
||||
*/
|
||||
private void purgeWorlds() {
|
||||
public void purgeWorlds() {
|
||||
if (this.worlds.size() <= 0)
|
||||
return;
|
||||
|
||||
@ -236,40 +236,41 @@ public class MultiverseCore extends JavaPlugin {
|
||||
List<String> animals = mvworld.getAnimalList();
|
||||
System.out.print("Monster Size:" + monsters.size() + " - " + "Animal Size: " + animals.size());
|
||||
for (Entity e : world.getEntities()) {
|
||||
String creatureName = e.toString().replaceAll("Craft", "").toLowerCase();
|
||||
// Check against Monsters
|
||||
if (e instanceof Creeper || e instanceof Skeleton || e instanceof Spider || e instanceof Zombie || e instanceof Ghast || e instanceof PigZombie || e instanceof Giant || e instanceof Slime || e instanceof Monster) {
|
||||
if (e instanceof Slime || e instanceof Monster) {
|
||||
// If Monsters are disabled and there's no exceptions we can simply remove them.
|
||||
if (mvworld.hasMonsters() == false && !(monsters.size() > 0)) {
|
||||
if (mvworld.allowMonsterSpawning() == false && !(monsters.size() > 0)) {
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
// If monsters are enabled and there's no exceptions we can continue to the next set.
|
||||
if (mvworld.hasMonsters() == true && !(monsters.size() > 0)) {
|
||||
if (mvworld.allowMonsterSpawning() == true && !(monsters.size() > 0)) {
|
||||
continue;
|
||||
}
|
||||
String creature = e.toString().replaceAll("Craft", "");
|
||||
if (monsters.contains(creature.toUpperCase())) {
|
||||
if (mvworld.hasMonsters()) {
|
||||
System.out.print(creature + " - Removed");
|
||||
|
||||
if (monsters.contains(creatureName.toUpperCase())) {
|
||||
if (mvworld.allowMonsterSpawning()) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check against Animals
|
||||
if (e instanceof Chicken || e instanceof Cow || e instanceof Sheep || e instanceof Pig || e instanceof Squid || e instanceof Animals) {
|
||||
// If Monsters are disabled and there's no exceptions we can simply remove them.
|
||||
if (mvworld.hasAnimals() == false && !(animals.size() > 0)) {
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
// If Animals are disabled and there's no exceptions we can simply remove them.
|
||||
if (mvworld.allowAnimalSpawning() == false && !(animals.size() > 0)) {
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
// If monsters are enabled and there's no exceptions we can continue to the next set.
|
||||
if (mvworld.hasAnimals() == true && !(animals.size() > 0)) {
|
||||
// If Animals are enabled and there's no exceptions we can continue to the next set.
|
||||
if (mvworld.allowAnimalSpawning() == true && !(animals.size() > 0)) {
|
||||
continue;
|
||||
}
|
||||
String creature = e.toString().replaceAll("Craft", "");
|
||||
if (animals.contains(creature.toUpperCase())) {
|
||||
if (mvworld.hasAnimals()) {
|
||||
if (animals.contains(creatureName.toUpperCase())) {
|
||||
if (mvworld.allowAnimalSpawning()) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
@ -301,6 +302,7 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.commandManager.addCommand(new ReloadCommand(this));
|
||||
this.commandManager.addCommand(new ModifyCommand(this));
|
||||
this.commandManager.addCommand(new EnvironmentCommand(this));
|
||||
this.commandManager.addCommand(new PurgeCommand(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,14 +36,8 @@ public class PurgeCommand extends BaseCommand {
|
||||
sender.sendMessage(this.usage);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> creatures = new ArrayList<String>();
|
||||
|
||||
for (String creature : args[0].toUpperCase().split(",")) {
|
||||
creatures.add(creature);
|
||||
}
|
||||
|
||||
new PurgeWorlds(plugin).purge(sender, p.getWorld(), creatures);
|
||||
System.out.println("Purged");
|
||||
this.plugin.purgeWorlds();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
package com.onarandombox.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Giant;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.PigZombie;
|
||||
import org.bukkit.entity.Sheep;
|
||||
@ -19,6 +22,7 @@ import org.bukkit.entity.Spider;
|
||||
import org.bukkit.entity.Squid;
|
||||
import org.bukkit.entity.Zombie;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
public class PurgeWorlds {
|
||||
@ -54,4 +58,56 @@ public class PurgeWorlds {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes the given world with it's settings
|
||||
*/
|
||||
public void purgeWorlds(MVWorld world) {
|
||||
|
||||
}
|
||||
|
||||
public void purgeWorlds(CommandSender sender, List<MVWorld> worlds, List<String> whatToKill) {
|
||||
if (worlds.isEmpty())
|
||||
return;
|
||||
|
||||
for (MVWorld mvworld : worlds) {
|
||||
World world = this.plugin.getServer().getWorld(mvworld.getName());
|
||||
if (world == null)
|
||||
continue;
|
||||
List<String> monsters = mvworld.getMonsterList();
|
||||
List<String> animals = mvworld.getAnimalList();
|
||||
System.out.print("Monster Size:" + monsters.size() + " - " + "Animal Size: " + animals.size());
|
||||
for (Entity e : world.getEntities()) {
|
||||
String creatureName = e.toString().replaceAll("Craft", "").toLowerCase();
|
||||
// Check against Monsters
|
||||
killMonster(mvworld, e, creatureName);
|
||||
// Check against Animals
|
||||
killCreature(mvworld, e, creatureName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean killCreature(MVWorld mvworld, Entity e, String creatureName) {
|
||||
String entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
if (entityName.contains(creatureName.toUpperCase())) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean killMonster(MVWorld mvworld, Entity e, String creatureName) {
|
||||
String entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
if (e instanceof Slime || e instanceof Monster) {
|
||||
if (entityName.contains(creatureName.toUpperCase())) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user