mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-25 12:06:17 +01:00
Started work to remake the gateway beacon cancelation
This commit is contained in:
parent
af28e22b58
commit
56bbd8f2ca
@ -4,6 +4,7 @@ import com.sekwah.advancedportals.compat.CraftBukkit;
|
|||||||
import com.sekwah.advancedportals.destinations.Destination;
|
import com.sekwah.advancedportals.destinations.Destination;
|
||||||
import com.sekwah.advancedportals.destinations.DestinationCommand;
|
import com.sekwah.advancedportals.destinations.DestinationCommand;
|
||||||
import com.sekwah.advancedportals.effects.WarpEffects;
|
import com.sekwah.advancedportals.effects.WarpEffects;
|
||||||
|
import com.sekwah.advancedportals.injector.PacketInjector;
|
||||||
import com.sekwah.advancedportals.listeners.*;
|
import com.sekwah.advancedportals.listeners.*;
|
||||||
import com.sekwah.advancedportals.metrics.Metrics;
|
import com.sekwah.advancedportals.metrics.Metrics;
|
||||||
import com.sekwah.advancedportals.portals.Portal;
|
import com.sekwah.advancedportals.portals.Portal;
|
||||||
@ -36,52 +37,11 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
this.compat = new CraftBukkit(this, version);
|
this.compat = new CraftBukkit(this, version);
|
||||||
|
|
||||||
|
ConfigAccessor config = new ConfigAccessor(this, "config.yml");
|
||||||
|
|
||||||
// This is a fix for my stupidity with the last version
|
if(config.getConfig().getBoolean("DisableGatewayBeam", true)) {
|
||||||
File dataFolder = this.getDataFolder();
|
new PacketInjector(this, version);
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
|
ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml");
|
||||||
portalConfig.saveDefaultConfig();
|
portalConfig.saveDefaultConfig();
|
||||||
|
@ -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 com.sekwah.advancedportals.reflection.ReflectionHelper;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -81,15 +82,9 @@ public class CraftBukkit {
|
|||||||
|
|
||||||
getTileEntityMethod = Class.forName(minecraftPackage + "WorldServer").getMethod("getTileEntity", blockPos);
|
getTileEntityMethod = Class.forName(minecraftPackage + "WorldServer").getMethod("getTileEntity", blockPos);
|
||||||
|
|
||||||
Field[] endGatewayFields = Class.forName(minecraftPackage + "TileEntityEndGateway").getDeclaredFields();
|
getEntityTimeoutField = ReflectionHelper.getFieldByType(Class.forName(minecraftPackage + "TileEntityEndGateway"), int.class, false);
|
||||||
|
if(getEntityTimeoutField != null) {
|
||||||
for(Field field : endGatewayFields) {
|
this.plugin.getLogger().info("Got field " + getEntityTimeoutField.getName() + " from TileEntityEndGateway");
|
||||||
if(field.getType() == int.class && !field.isAccessible()) {
|
|
||||||
field.setAccessible(true);
|
|
||||||
getEntityTimeoutField = field;
|
|
||||||
this.plugin.getLogger().info("Got field " + field.getName() + " from TileEntityEndGateway");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -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 + ".";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,7 +18,7 @@ public class PortalPlacer implements Listener {
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final AdvancedPortalsPlugin plugin;
|
private final AdvancedPortalsPlugin plugin;
|
||||||
private final boolean DISABLE_GATEWAY_BEAM;
|
//private final boolean DISABLE_GATEWAY_BEAM;
|
||||||
|
|
||||||
public PortalPlacer(AdvancedPortalsPlugin plugin) {
|
public PortalPlacer(AdvancedPortalsPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -26,7 +26,7 @@ public class PortalPlacer implements Listener {
|
|||||||
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
|
||||||
boolean portalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
|
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) {
|
if (portalPlace) {
|
||||||
@ -50,18 +50,18 @@ 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) {
|
/*if(this.DISABLE_GATEWAY_BEAM) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||||
this.plugin.compat.setGatewayAgeHigh(event.getBlock());
|
this.plugin.compat.setGatewayAgeHigh(event.getBlock());
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
/*@EventHandler
|
||||||
public void onChunkLoad(ChunkLoadEvent event) {
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
if(!this.DISABLE_GATEWAY_BEAM) {
|
if(!this.DISABLE_GATEWAY_BEAM) {
|
||||||
return;
|
return;
|
||||||
@ -71,7 +71,7 @@ public class PortalPlacer implements Listener {
|
|||||||
this.plugin.compat.setGatewayAgeHigh(block.getBlock());
|
this.plugin.compat.setGatewayAgeHigh(block.getBlock());
|
||||||
}
|
}
|
||||||
//event.getHandlers();
|
//event.getHandlers();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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.
|
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
|
# 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.
|
# 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user