Skip to content

Commit

Permalink
fix some bugs that could make ZLobby can't be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRichard4096 committed Jan 28, 2025
1 parent c3364e7 commit ca56adb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
19 changes: 12 additions & 7 deletions src/main/java/com/john4096/zLOBBY/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockEvent;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
Expand Down Expand Up @@ -41,17 +43,16 @@ public void onEnable() {
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();
logger.info("EventHandler loaded");
}
@EventHandler(priority = EventPriority.HIGHEST)
public void preProcessing(Event event){
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();
this.config = ZLOBBY.getPlugin(ZLOBBY.class).getConfig();
}



@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();
this.config = ZLOBBY.getPlugin(ZLOBBY.class).getConfig();
this.TPL = loadTPLocation();
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();

boolean enable = config.getBoolean("onPlayerJoin.enable");
this.Debug = ZLOBBY.getPlugin(ZLOBBY.class).Debug;
Location location = player.getLocation();
Expand Down Expand Up @@ -302,8 +303,8 @@ public void onPlayerRespawn(PlayerRespawnEvent event){
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();
this.Debug = ZLOBBY.getPlugin(ZLOBBY.class).Debug;
this.config = ZLOBBY.getPlugin(ZLOBBY.class).getConfig();
this.Debug = ZLOBBY.getPlugin(ZLOBBY.class).Debug;
Player player = event.getPlayer();
boolean enable = config.getBoolean("Lobby.enable");
if (!enable){
Expand All @@ -330,6 +331,7 @@ public void onBlockBreak(BlockBreakEvent event) {
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();
this.config = ZLOBBY.getPlugin(ZLOBBY.class).getConfig();
this.Debug = ZLOBBY.getPlugin(ZLOBBY.class).Debug;
Player player = event.getPlayer();
Expand Down Expand Up @@ -361,6 +363,8 @@ public void onBlockPlace(BlockPlaceEvent event) {
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();
this.config = ZLOBBY.getPlugin(ZLOBBY.class).getConfig();
this.Debug = ZLOBBY.getPlugin(ZLOBBY.class).Debug;
Player player = event.getPlayer();
Location location = player.getLocation();
Expand All @@ -381,6 +385,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
this.Debug = ZLOBBY.getPlugin(ZLOBBY.class).Debug;
this.onJoinConfig = ZLOBBY.getPlugin(ZLOBBY.class).getOnJoinConfig();
this.config = ZLOBBY.getPlugin(ZLOBBY.class).getConfig();
Player player;
try {
Expand Down
26 changes: 19 additions & 7 deletions src/main/java/com/john4096/zLOBBY/ZLOBBY.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.john4096.zLOBBY;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -13,22 +14,30 @@
public final class ZLOBBY extends JavaPlugin {
public boolean Debug = false;
private final Logger logger = getLogger();
private final String version = "0.1";
private final String version = getDescription().getVersion();
public FileConfiguration config;
public YamlConfiguration onJoinConfig;
private File onJoinFile = new File(getDataFolder(), "onJoin.yml");
public EventListener eventListener = new EventListener();
@Override
public void onEnable() {
final String version = this.version;

// Plugin startup logic
logger.info("Loading Simple ZCraft Lobby plugin");
logger.info("""
\033[31m
\s
,---,| | | \s
.-' | ,---.|---.|---., .
| | | || || || |
`---'`---'`---'`---'`---'`---|
`---'
\033[0m""");
logger.info("Running on version"+version);

eventListener.onEnable();
Bukkit.getPluginManager().registerEvents(eventListener, this);
logger.info("Listener loaded");
if(version.toLowerCase().contains("dev")){
logger.warning("You are running a development version of the plugin, please do not use it in a production environment");
logger.warning("See the latest build on https://jenkins.micro-wave.cc/job/ZLobby/");
}
logger.info("Loading config......");
saveDefaultConfig();
if (!onJoinFile.exists()){
Expand All @@ -39,6 +48,10 @@ public void onEnable() {
logger.info("Loading listener class......");
Bukkit.getPluginCommand("zlobby").setExecutor(new Executor());
Bukkit.getPluginCommand("zlobby").setTabCompleter(new CommandTabCompleter());
EventListener eventListener = new EventListener();
eventListener.onEnable();
Bukkit.getPluginManager().registerEvents(eventListener, this);
logger.info("Listener loaded");
logger.info("Loading BStats......");
int pluginId = 24574;
Metrics metrics = new Metrics(this, pluginId);
Expand Down Expand Up @@ -66,7 +79,6 @@ public void reloadConfig() {
if (!this.onJoinFile.exists()){
saveResource("onJoin.yml",false);
}

this.onJoinConfig = YamlConfiguration.loadConfiguration(onJoinFile);
}

Expand Down

0 comments on commit ca56adb

Please sign in to comment.