fixed player interactions in world and added default world for joining
This commit is contained in:
parent
52b37d1094
commit
7091db6484
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
|
@ -14,9 +14,11 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
private static Main instance;
|
||||
private static final Logger LOGGER = Bukkit.getLogger();
|
||||
|
||||
private final List<ViewableWorld> worlds = new ArrayList<>();
|
||||
|
||||
@ -50,13 +52,11 @@ public class Main extends JavaPlugin {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
worldFolder.mkdirs();
|
||||
Arrays.stream(Objects.requireNonNull(worldFolder.listFiles())).forEach(file -> {
|
||||
Bukkit.getLogger().info("[Worldmuseum] Loading world " + file.getName());
|
||||
LOGGER.info("[Worldmuseum] Loading world " + file.getName());
|
||||
if (file.isDirectory()) this.worlds.add(new ViewableWorld(file));
|
||||
else Bukkit.getLogger().info( "[Worldmuseum] " + file.getName() + " is not a valid world!");
|
||||
else LOGGER.info( "[Worldmuseum] " + file.getName() + " is not a valid world!");
|
||||
});
|
||||
this.worlds.forEach(ViewableWorld::loadWorld);
|
||||
for(ViewableWorld viewableWorld : this.worlds) viewableWorld.getWorld().setAutoSave(false);
|
||||
|
||||
}
|
||||
|
||||
public static Main instance() {
|
||||
|
@ -4,17 +4,24 @@ import eu.mhsl.minecraft.WorldMuseum.Main;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
event.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||
Main.instance().getWorlds().forEach(world -> {
|
||||
if (world.isDefaultWorld()) world.addViewer(event.getPlayer());
|
||||
});
|
||||
event.getPlayer().addPotionEffect(
|
||||
new PotionEffect(PotionEffectType.HASTE, PotionEffect.INFINITE_DURATION, 15, false, false, false)
|
||||
);
|
||||
@ -22,10 +29,15 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBreak(BlockBreakEvent event) {
|
||||
Material material = event.getBlock().getType();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(
|
||||
Main.instance(),
|
||||
() -> event.getBlock().getWorld().getBlockAt(event.getBlock().getLocation()).setType(event.getBlock().getType()),
|
||||
Ticks.TICKS_PER_SECOND * 5
|
||||
() -> Objects.requireNonNull(Bukkit.getWorld(event.getBlock().getWorld().getName())).setType(event.getBlock().getLocation(), material), Ticks.TICKS_PER_SECOND * 5
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlace(BlockPlaceEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ public class ViewableWorld {
|
||||
private boolean enabled = true;
|
||||
private String name;
|
||||
private Material icon = Material.GRASS_BLOCK;
|
||||
private boolean isDefaultWorld = false;
|
||||
|
||||
public ViewableWorld(File worldLocation) {
|
||||
this.worldLocation = worldLocation;
|
||||
@ -31,14 +32,17 @@ public class ViewableWorld {
|
||||
this.enabled = config.getBoolean("enabled");
|
||||
this.name = config.getString("name");
|
||||
this.icon = Material.valueOf(config.getString("icon"));
|
||||
this.isDefaultWorld = config.getBoolean("isDefaultWorld");
|
||||
} else {
|
||||
System.out.println("[WorldMuseum] Could not find config.yml");
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
configFile.createNewFile();
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(configFile);
|
||||
data.set("enabled", false);
|
||||
data.set("name", this.name);
|
||||
data.set("icon", this.icon.name());
|
||||
data.set("isDefaultWorld", false);
|
||||
data.save(configFile);
|
||||
|
||||
} catch (IOException e) {e.printStackTrace();}
|
||||
@ -53,6 +57,7 @@ public class ViewableWorld {
|
||||
this.world = worldCreator.createWorld();
|
||||
Objects.requireNonNull(this.world);
|
||||
this.world.setAutoSave(false);
|
||||
// Bukkit.unloadWorld(this.world, false);
|
||||
}
|
||||
|
||||
public void unloadWorld() {
|
||||
@ -76,7 +81,7 @@ public class ViewableWorld {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
public boolean isDefaultWorld() {
|
||||
return isDefaultWorld;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user