Added new value to disable beacon

This commit is contained in:
Sekwah 2018-08-27 21:43:02 +01:00
parent d491009451
commit e6c2b2e960
9 changed files with 80 additions and 14 deletions

View File

@ -4,7 +4,7 @@ apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'com.sekwah.advancedportals'
version = '0.0.45-snapshot'
version = '0.0.46-snapshot'
description = ""
@ -38,7 +38,7 @@ task runJar() {
javaexec {
main "-jar"
args "${System.env.MC_SERVER_LOC}\\${System.env.MC_SERVER_JAR}.jar"
jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -DIReallyKnowWhatIAmDoingISwear=true"
jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
workingDir "${System.env.MC_SERVER_LOC}"
}
}

View File

@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.0.45
version: 0.0.46
author: sekwah41
description: An advanced portals plugin for bukkit.
api-version: 1.13

View File

@ -1,6 +1,7 @@
package com.sekwah.advancedportals.compat;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.lang.reflect.Constructor;
@ -19,8 +20,8 @@ import java.lang.reflect.Method;
public class CraftBukkit {
private final AdvancedPortalsPlugin plugin;
private Constructor<?> reallyOldChatConstructor;
// Data for chat bar and json message
private Method chatMessageTypeMethod;
private Method serializeMessage;
@ -31,7 +32,13 @@ public class CraftBukkit {
private Method sendPacket;
// Classes so it doesnt keep fetching them.
// Data for beacon
private Class<?> endGatewayClass;
private Class<?> tileEntityEndGatewayClass;
private Constructor<?> blockPositionConstructor;
private Method getWorldHandleMethod;
private Method getTileEntityMethod;
public CraftBukkit(AdvancedPortalsPlugin plugin, String bukkitImpl) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
@ -59,6 +66,21 @@ public class CraftBukkit {
this.playerConnection = Class.forName(minecraftPackage + "EntityPlayer").getField("playerConnection"); // get player connection
Class<?> packet = Class.forName(minecraftPackage + "Packet");
this.sendPacket = playerConnection.getType().getMethod("sendPacket", packet);
// Data for beacon
this.endGatewayClass = Class.forName(craftBukkitPackage + "block.CraftEndGateway");
this.tileEntityEndGatewayClass = Class.forName(minecraftPackage + "TileEntityEndGateway");
Class<?> blockPos = Class.forName(minecraftPackage + "BlockPosition");
this.blockPositionConstructor = blockPos.getConstructor(int.class, int.class, int.class);
getWorldHandleMethod = Class.forName(craftBukkitPackage + "CraftWorld").getMethod("getHandle");
getTileEntityMethod = Class.forName(minecraftPackage + "WorldServer").getMethod("getTileEntity", blockPos);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().warning("Attempting to use backup porekit locations");
@ -107,4 +129,24 @@ public class CraftBukkit {
}
/**
* Blocks the beacon from showing
* @param block
*/
public void setGatewayAgeHigh(Block block) {
if(block.getState().getClass().isAssignableFrom(this.endGatewayClass)) {
try {
Object tileEntity = this.getTileEntityMethod.invoke(this.getWorldHandleMethod.invoke(block.getWorld()),
this.blockPositionConstructor.newInstance(block.getX(), block.getY(), block.getZ()));
if(tileEntity.getClass().isAssignableFrom(this.tileEntityEndGatewayClass)) {
Field f = tileEntity.getClass().getDeclaredField("f");
f.setAccessible(true);
f.set(tileEntity, Integer.MAX_VALUE);
}
} catch (IllegalAccessException| InvocationTargetException | InstantiationException | NoSuchFieldException e) {
this.plugin.getLogger().warning("Error setting gateway time");
e.printStackTrace();
}
}
}
}

View File

@ -8,6 +8,7 @@ import com.sekwah.advancedportals.portals.AdvancedPortal;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Orientable;
@ -262,7 +263,6 @@ public class Listeners implements Listener {
if(block instanceof Orientable) {
Orientable rotatable = (Orientable) block;
System.out.println(rotatable.getAxis());
if (rotatable.getAxis() == Axis.X) {
rotatable.setAxis(Axis.Z);
} else {

View File

@ -3,30 +3,33 @@ package com.sekwah.advancedportals.listeners;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.ConfigAccessor;
import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.ChunkLoadEvent;
public class PortalPlacer implements Listener {
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
// 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;
private final boolean DISABLE_GATEWAY_BEAM;
public PortalPlacer(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
boolean portalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
if (PortalPlace) {
this.DISABLE_GATEWAY_BEAM = config.getConfig().getBoolean("DisableGatewayBeam");
if (portalPlace) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
@ -47,11 +50,29 @@ public class PortalPlacer implements Listener {
}
else if (name.equals("\u00A78Gateway Block Placer")){
event.getBlockPlaced().setType(Material.END_GATEWAY);
if(this.DISABLE_GATEWAY_BEAM) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
this.plugin.compat.setGatewayAgeHigh(event.getBlock());
}, 1);
}
}
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
if(!this.DISABLE_GATEWAY_BEAM) {
return;
}
BlockState[] tileEntities = event.getChunk().getTileEntities();
for(BlockState block : tileEntities) {
this.plugin.compat.setGatewayAgeHigh(block.getBlock());
}
//event.getHandlers();
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock();

View File

@ -16,6 +16,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.List;
public class PortalProtect implements Listener {
@SuppressWarnings("unused")

View File

@ -472,7 +472,7 @@ public class Portal {
private static void failSound(Player player, AdvancedPortal portal) {
if(!(portal.getTrigger() == Material.NETHER_PORTAL && player.getGameMode() == GameMode.CREATIVE)){
player.playSound(player.getLocation(), portalSound, 0.5f, new Random().nextFloat() * 0.4F + 0.8F);
player.playSound(player.getLocation(), portalSound, 0.2f, new Random().nextFloat() * 0.4F + 0.8F);
}
}

View File

@ -69,6 +69,8 @@ BlockSpectatorMode: false
PortalCooldown: 5 # How long after trying to enter a portal until the player can try to enter another. 0 or lower to deactivate.
ThrowbackAmount: 0.7 # How fast to throw them back, 0 or lower to disable throwback
DisableGatewayBeam: true
# Letters are flags. Include them to activate. n always disables everything, remove if you want it to work.
# Lettering may not make too much sense but meh its useful. Examples are "ocpk" or "cop" (doesnt matter order)
#

View File

@ -1,6 +1,6 @@
main: com.sekwah.advancedportals.AdvancedPortalsPlugin
name: AdvancedPortals
version: 0.0.45
version: 0.0.46
author: sekwah41
description: An advanced portals plugin for bukkit.
api-version: 1.13