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