Added stuff for backporting the new versions

This commit is contained in:
Sekwah 2018-08-29 00:26:23 +01:00
parent 5de6385051
commit f658776315
6 changed files with 80 additions and 3 deletions

View File

@ -75,6 +75,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. 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 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. # 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) # 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 main: com.sekwah.advancedportals.AdvancedPortalsPlugin
name: AdvancedPortals name: AdvancedPortals
version: 0.0.41 version: 0.0.46
author: sekwah41 author: sekwah41
description: An advanced portals plugin for bukkit. description: An advanced portals plugin for bukkit.
commands: commands:

12
pom.xml
View File

@ -9,6 +9,16 @@
<directory>${basedir}/Resources</directory> <directory>${basedir}/Resources</directory>
</resource> </resource>
</resources> </resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build> </build>
<repositories> <repositories>
<repository> <repository>
@ -16,7 +26,7 @@
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository> </repository>
</repositories> </repositories>
<version>0.0.41-snapshot</version> <version>0.0.46-1.8-1.12-snapshot</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>

View File

@ -55,7 +55,6 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
if (sender.hasPermission("advancedportals.portal")) { if (sender.hasPermission("advancedportals.portal")) {
if (args.length > 0) { switch (args[0].toLowerCase()) { if (args.length > 0) { switch (args[0].toLowerCase()) {
case "wand":
case "warp": case "warp":
if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")){ if (args.length == 2 && player.hasPermission("advancedportals.portal.warp")){
for (AdvancedPortal portal: Portal.portals){ for (AdvancedPortal portal: Portal.portals){
@ -296,6 +295,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal");
break; break;
case "wand":
case "select": case "select":
// TODO finish the select command and the hit block to replace! // TODO finish the select command and the hit block to replace!
if (!player.hasMetadata("selectingPortal")) { if (!player.hasMetadata("selectingPortal")) {

View File

@ -1,6 +1,7 @@
package com.sekwah.advancedportals.compat; package com.sekwah.advancedportals.compat;
import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -32,6 +33,13 @@ public class CraftBukkit {
private boolean useEnumType = false; private boolean useEnumType = false;
// Data for beacon
private Class<?> endGatewayClass;
private Class<?> tileEntityEndGatewayClass;
private Constructor<?> blockPositionConstructor;
private Method getWorldHandleMethod;
private Method getTileEntityMethod;
// Classes so it doesnt keep fetching them. // Classes so it doesnt keep fetching them.
@ -80,6 +88,19 @@ public class CraftBukkit {
this.playerConnection = Class.forName(minecraftPackage + "EntityPlayer").getField("playerConnection"); // get player connection this.playerConnection = Class.forName(minecraftPackage + "EntityPlayer").getField("playerConnection"); // get player connection
Class<?> packet = Class.forName(minecraftPackage + "Packet"); Class<?> packet = Class.forName(minecraftPackage + "Packet");
this.sendPacket = playerConnection.getType().getMethod("sendPacket", 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
plugin.getLogger().warning("Attempting to use backup porekit locations"); plugin.getLogger().warning("Attempting to use backup porekit locations");
@ -144,5 +165,21 @@ public class CraftBukkit {
return null; return null;
} }
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 g = tileEntity.getClass().getDeclaredField("g");
g.setAccessible(true);
g.set(tileEntity, Integer.MAX_VALUE);
}
} catch (IllegalAccessException| InvocationTargetException | InstantiationException | NoSuchFieldException e) {
this.plugin.getLogger().warning("Error setting gateway time");
e.printStackTrace();
}
}
}
} }

View File

@ -3,18 +3,22 @@ package com.sekwah.advancedportals.listeners;
import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.ConfigAccessor; import com.sekwah.advancedportals.ConfigAccessor;
import com.sekwah.advancedportals.portals.Portal; import com.sekwah.advancedportals.portals.Portal;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.ChunkLoadEvent;
public class PortalPlacer implements Listener { public class PortalPlacer implements Listener {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin; private final AdvancedPortalsPlugin plugin;
private final boolean DISABLE_GATEWAY_BEAM;
// The needed config values will be stored so they are easier to access later // 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... // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("<EFBFBD>eP...
@ -26,6 +30,8 @@ public class PortalPlacer implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock"); this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
this.DISABLE_GATEWAY_BEAM = config.getConfig().getBoolean("DisableGatewayBeam", true);
if (PortalPlace) { if (PortalPlace) {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
@ -47,11 +53,33 @@ public class PortalPlacer implements Listener {
} }
else if (name.equals("\u00A78Gateway Block Placer")){ else if (name.equals("\u00A78Gateway Block Placer")){
event.getBlockPlaced().setType(Material.END_GATEWAY); 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;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
BlockState[] tileEntities = event.getChunk().getTileEntities();
if(tileEntities.length >0) {
System.out.println("TILE ENTITIES");
}
for(BlockState block : tileEntities) {
this.plugin.compat.setGatewayAgeHigh(block.getBlock());
}
}, 10);
//event.getHandlers();
}
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) { public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();