prevent nether portal use and entity damage

This commit is contained in:
Elias Müller 2024-09-21 16:40:09 +02:00
parent 75a0f8a1ef
commit 139ff42250
5 changed files with 32 additions and 11 deletions

View File

@ -30,6 +30,6 @@ tasks.register<Exec>("copyJarToTestServer") {
dependsOn(tasks.jar) dependsOn(tasks.jar)
mustRunAfter(tasks.jar) mustRunAfter(tasks.jar)
commandLine("cp", "build/libs/WorldMuseum-1.0-SNAPSHOT.jar", "/Users/olischma/Desktop/paper/plugins") commandLine("cp", "build/libs/WorldMuseum-1.0-SNAPSHOT.jar", "/media/elias/Backup/world-museum/plugins")
} }

View File

@ -20,14 +20,14 @@ import java.util.logging.Logger;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
private static Main instance; private static Main instance;
private static Logger LOGGER; private static Logger logger;
private final List<ViewableWorld> worlds = new ArrayList<>(); private final List<ViewableWorld> worlds = new ArrayList<>();
@Override @Override
public void onEnable() { public void onEnable() {
Main.instance = this; Main.instance = this;
LOGGER = getLogger(); logger = logger();
this.saveDefaultConfig(); this.saveDefaultConfig();
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
@ -47,11 +47,10 @@ public class Main extends JavaPlugin {
public void onDisable() { public void onDisable() {
this.worlds.forEach(ViewableWorld::unloadWorld); this.worlds.forEach(ViewableWorld::unloadWorld);
} }
@Override @Override
public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) { public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
return new ChunkGenerator() { return new ChunkGenerator() {};
};
} }
private void loadWorlds() { private void loadWorlds() {
@ -61,9 +60,12 @@ public class Main extends JavaPlugin {
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
worldFolder.mkdirs(); worldFolder.mkdirs();
Arrays.stream(Objects.requireNonNull(worldFolder.listFiles())).forEach(file -> { Arrays.stream(Objects.requireNonNull(worldFolder.listFiles())).forEach(file -> {
LOGGER.info("[Worldmuseum] Loading world " + file.getName()); logger.info("[Worldmuseum] Loading world " + file.getName());
if (file.isDirectory()) this.worlds.add(new ViewableWorld(file)); if (file.isDirectory()) {
else LOGGER.info( "[Worldmuseum] " + file.getName() + " is not a valid world!"); this.worlds.add(new ViewableWorld(file));
} else {
logger.info( "[Worldmuseum] " + file.getName() + " is not a directory and therefore not a valid world!");
}
}); });
this.worlds.forEach(ViewableWorld::loadWorld); this.worlds.forEach(ViewableWorld::loadWorld);
} }
@ -75,4 +77,9 @@ public class Main extends JavaPlugin {
public List<ViewableWorld> getWorlds() { public List<ViewableWorld> getWorlds() {
return worlds; return worlds;
} }
public static Logger logger() {
if(logger == null) throw new RuntimeException("Plugin not initialized yet");
return logger;
}
} }

View File

@ -12,7 +12,7 @@ import java.util.logging.Level;
public class BungeeCord { public class BungeeCord {
public static void connect(Player player, String server) { public static void connect(Player player, String server) {
Main.instance().getLogger().log(Level.INFO, String.format("Bungeecord: Sending %s to %s", player.getName(), server)); Main.logger().log(Level.INFO, String.format("Bungeecord: Sending %s to %s", player.getName(), server));
ByteArrayDataOutput output = ByteStreams.newDataOutput(); ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeUTF("Connect"); output.writeUTF("Connect");
output.writeUTF(server); output.writeUTF(server);

View File

@ -1,5 +1,6 @@
package eu.mhsl.minecraft.WorldMuseum.viewableWorld; package eu.mhsl.minecraft.WorldMuseum.viewableWorld;
import eu.mhsl.minecraft.WorldMuseum.Main;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.TriState; import net.kyori.adventure.util.TriState;
import org.bukkit.*; import org.bukkit.*;
@ -13,6 +14,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level;
public class ViewableWorld { public class ViewableWorld {
private final File worldLocation; private final File worldLocation;
@ -45,7 +47,9 @@ public class ViewableWorld {
data.set("isDefaultWorld", false); data.set("isDefaultWorld", false);
data.save(configFile); data.save(configFile);
} catch (IOException e) {e.printStackTrace();} } catch (IOException e) {
Main.logger().log(Level.SEVERE, "Failed creating Configuration File", e);
}
} }
} }

View File

@ -6,7 +6,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent; import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
public class ViewableWorldListener implements Listener { public class ViewableWorldListener implements Listener {
@ -34,4 +36,12 @@ public class ViewableWorldListener implements Listener {
public void onChunkUnload(ChunkUnloadEvent event) { public void onChunkUnload(ChunkUnloadEvent event) {
event.setSaveChunk(false); event.setSaveChunk(false);
} }
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
event.setCancelled(true);
}
@EventHandler
public void preventPortal(PlayerPortalEvent event) {
event.setCancelled(true);
}
} }