Started work to remake the gateway beacon cancelation

This commit is contained in:
Sekwah 2018-10-18 03:27:10 +01:00
parent af28e22b58
commit 56bbd8f2ca
6 changed files with 48 additions and 60 deletions

View File

@ -4,6 +4,7 @@ import com.sekwah.advancedportals.compat.CraftBukkit;
import com.sekwah.advancedportals.destinations.Destination;
import com.sekwah.advancedportals.destinations.DestinationCommand;
import com.sekwah.advancedportals.effects.WarpEffects;
import com.sekwah.advancedportals.injector.PacketInjector;
import com.sekwah.advancedportals.listeners.*;
import com.sekwah.advancedportals.metrics.Metrics;
import com.sekwah.advancedportals.portals.Portal;
@ -36,53 +37,12 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
this.compat = new CraftBukkit(this, version);
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
// This is a fix for my stupidity with the last version
File dataFolder = this.getDataFolder();
File configFile = new File(dataFolder, "portals.yml");
InputStreamReader inr = null;
try {
inr = new InputStreamReader(new FileInputStream(configFile), "ASCII");
BufferedReader br = new BufferedReader(inr);
StringBuffer sb = new StringBuffer();
while (true) {
String line = br.readLine();
if (line == null)
break;
sb.append(line);
sb.append("\n");
}
br.close();
inr.close();
String fileContents = sb.toString();
fileContents = fileContents.replaceAll(" getPos1\\(\\):", " pos1:");
fileContents = fileContents.replaceAll(" getPos2\\(\\):", " pos2:");
fileContents = fileContents.replaceAll(" getBungee\\(\\):", " bungee:");
try {
FileWriter fileWriter = new FileWriter(configFile);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(fileContents);
bufferedWriter.flush();
bufferedWriter.close();
fileWriter.close();
}
catch(IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
this.getLogger().warning("Invalid Encoding");
} catch (FileNotFoundException e) {
this.getLogger().info("File not found");
} catch (IOException e) {
e.printStackTrace();
if(config.getConfig().getBoolean("DisableGatewayBeam", true)) {
new PacketInjector(this, version);
}
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
portalConfig.saveDefaultConfig();

View File

@ -1,6 +1,7 @@
package com.sekwah.advancedportals.compat;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
import com.sekwah.advancedportals.reflection.ReflectionHelper;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -81,15 +82,9 @@ public class CraftBukkit {
getTileEntityMethod = Class.forName(minecraftPackage + "WorldServer").getMethod("getTileEntity", blockPos);
Field[] endGatewayFields = Class.forName(minecraftPackage + "TileEntityEndGateway").getDeclaredFields();
for(Field field : endGatewayFields) {
if(field.getType() == int.class && !field.isAccessible()) {
field.setAccessible(true);
getEntityTimeoutField = field;
this.plugin.getLogger().info("Got field " + field.getName() + " from TileEntityEndGateway");
return;
}
getEntityTimeoutField = ReflectionHelper.getFieldByType(Class.forName(minecraftPackage + "TileEntityEndGateway"), int.class, false);
if(getEntityTimeoutField != null) {
this.plugin.getLogger().info("Got field " + getEntityTimeoutField.getName() + " from TileEntityEndGateway");
}
} catch (Exception e) {

View File

@ -0,0 +1,14 @@
package com.sekwah.advancedportals.injector;
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
public class PacketInjector {
public PacketInjector(AdvancedPortalsPlugin plugin, String bukkitImpl) {
String craftBukkitPackage = "org.bukkit.craftbukkit." + bukkitImpl + ".";
String minecraftPackage = "net.minecraft.server." + bukkitImpl + ".";
}
}

View File

@ -18,7 +18,7 @@ public class PortalPlacer implements Listener {
@SuppressWarnings("unused")
private final AdvancedPortalsPlugin plugin;
private final boolean DISABLE_GATEWAY_BEAM;
//private final boolean DISABLE_GATEWAY_BEAM;
public PortalPlacer(AdvancedPortalsPlugin plugin) {
this.plugin = plugin;
@ -26,7 +26,7 @@ public class PortalPlacer implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
boolean portalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
this.DISABLE_GATEWAY_BEAM = config.getConfig().getBoolean("DisableGatewayBeam", true);
//this.DISABLE_GATEWAY_BEAM = config.getConfig().getBoolean("DisableGatewayBeam", true);
if (portalPlace) {
@ -50,18 +50,18 @@ public class PortalPlacer implements Listener {
}
else if (name.equals("\u00A78Gateway Block Placer")){
event.getBlockPlaced().setType(Material.END_GATEWAY);
if(this.DISABLE_GATEWAY_BEAM) {
/*if(this.DISABLE_GATEWAY_BEAM) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
this.plugin.compat.setGatewayAgeHigh(event.getBlock());
}, 1);
}
}*/
}
}
}
@EventHandler
/*@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
if(!this.DISABLE_GATEWAY_BEAM) {
return;
@ -71,7 +71,7 @@ public class PortalPlacer implements Listener {
this.plugin.compat.setGatewayAgeHigh(block.getBlock());
}
//event.getHandlers();
}
}*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {

View File

@ -0,0 +1,17 @@
package com.sekwah.advancedportals.reflection;
import java.lang.reflect.Field;
public class ReflectionHelper {
public static Field getFieldByType(Class<?> clazz, Class<?> findingType, boolean isAccessable) {
Field[] fields = clazz.getDeclaredFields();
for(Field field : fields) {
if(field.getType() == findingType && field.isAccessible() == isAccessable) {
field.setAccessible(true);
return field;
}
}
return null;
}
}

View File

@ -69,7 +69,9 @@ 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
# Experimental, works but not all the time (Entities don't seem to be provided in the event sometimes or something is wrong)
# We have no plans to further this but if anyone has any tips feel free to contact us here https://discord.gg/25QZVVn
DisableGatewayBeam: false
# 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)