Added anti pig spawning

This commit is contained in:
Alastair 2017-11-30 18:56:42 +00:00
parent 734337a5be
commit 4dcb4dd354
5 changed files with 22 additions and 24 deletions

View File

@ -16,6 +16,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.*;
@ -84,6 +85,13 @@ public class Listeners implements Listener {
Portal.cooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
}
@EventHandler
public void spawnMobEvent(CreatureSpawnEvent event) {
if(event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL && Portal.inPortalRegion(event.getLocation(), Portal.getPortalProtectionRadius())) {
event.setCancelled(true);
}
}
@EventHandler
public void onLeaveEvent(PlayerQuitEvent event) {
Portal.cooldown.remove(event.getPlayer().getName());

View File

@ -16,8 +16,6 @@ public class PortalPlacer implements Listener {
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
private final int PortalProtectionRadius;
// The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
private boolean PortalPlace = true;
@ -28,8 +26,6 @@ public class PortalPlacer implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
this.PortalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius");
if (PortalPlace) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@ -60,7 +56,7 @@ public class PortalPlacer implements Listener {
public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock();
Material material = block.getType();
if (material == Material.PORTAL && Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius))
if (material == Material.PORTAL && Portal.inPortalRegion(block.getLocation(), Portal.getPortalProtectionRadius()))
event.setCancelled(true);
}
}

View File

@ -30,8 +30,6 @@ public class PortalProtect implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.PortalProtect = config.getConfig().getBoolean("PortalProtection");
this.PortalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius");
if (PortalProtect) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

View File

@ -36,25 +36,13 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.lang.reflect.Method;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;

View File

@ -32,12 +32,16 @@ public class Portal {
private static int cooldelay;
private static double throwback;
private static Sound portalSound;
private static int portalProtectionRadius;
public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
showBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
cooldelay = config.getConfig().getInt("PortalCooldown", 5);
throwback = config.getConfig().getDouble("ThrowbackAmount", 0.7);
this.showBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
this.cooldelay = config.getConfig().getInt("PortalCooldown", 5);
this.portalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius");
this.throwback = config.getConfig().getDouble("ThrowbackAmount", 0.7);
this.portalSound = WarpEffects.findSound(plugin, "BLOCK_PORTAL_TRAVEL", "PORTAL_TRAVEL");
@ -566,4 +570,8 @@ public class Portal {
player.setVelocity(velocity.setY(0).normalize().multiply(-1).setY(throwback));
}
}
public static int getPortalProtectionRadius() {
return portalProtectionRadius;
}
}