Skip to content

Commit

Permalink
Implement workaround for PaperMC/Paper#5992
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Jun 6, 2022
1 parent 740c283 commit 0d9093e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ch.andre601</groupId>
<artifactId>IAxPresenceFootsteps</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import ch.andre601.iaxpresencefootsteps.commands.PFCreate;
import ch.andre601.iaxpresencefootsteps.commands.PFReload;
import ch.andre601.iaxpresencefootsteps.events.ServerEvents;
import ch.andre601.iaxpresencefootsteps.util.JsonCreator;

import ch.andre601.iaxpresencefootsteps.util.message.MessageUtil;
import ch.andre601.iaxpresencefootsteps.util.message.PaperMessageUtil;
import ch.andre601.iaxpresencefootsteps.util.message.SpigotMessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.PluginManager;
Expand All @@ -16,39 +16,32 @@
public class IAxPresenceFootsteps extends JavaPlugin{
private MessageUtil messageUtil;
private JsonCreator jsonCreator;

private ConsoleCommandSender console;

@Override
public void onEnable(){
public void onLoad(){
saveDefaultConfig();
this.console = Bukkit.getConsoleSender();

try{
Class.forName("io.papermc.paper.text.PaperComponents");

messageUtil = new PaperMessageUtil(this);
getMessageUtil().sendMessage("<grey>Found PaperMC. Using native message system from it...");
}catch(ClassNotFoundException ex){
messageUtil = new SpigotMessageUtils(this);
getMessageUtil().sendMessage("<grey>Found SpigotMC. Using BukkitAudiences from Kyori Adventure...");
}

PluginManager manager = getServer().getPluginManager();
if(!manager.isPluginEnabled("ItemsAdder")){
getMessageUtil().sendMessage("<red>ItemsAdder was not found! IAxPresenceFootsteps requires this plugin to work.");
manager.disablePlugin(this);
return;
}
console = getServer().getConsoleSender();

jsonCreator = new JsonCreator(this);

if(!loadCommands()){
manager.disablePlugin(this);
return;
}
loadMessageUtil();
}

@Override
public void onEnable(){
getMessageUtil().sendMessage("<grey>Preparing IAxPresenceFootsteps...");
try{
Class.forName("org.bukkit.event.server.ServerLoadEvent");

getMessageUtil().sendMessage("<green>IAxPresenceFootsteps ready!");
new ServerEvents(this);
}catch(ClassNotFoundException ex){
// I doubt people use IA on a server that isn't the latest 3, but you never know...
getServer().getScheduler().runTaskLater(this, this::startPlugin, 1L);
}

getMessageUtil().sendMessage("<grey>Completed preparation. Waiting for Server to finish...");
}

public MessageUtil getMessageUtil(){
Expand All @@ -63,6 +56,35 @@ public ConsoleCommandSender getConsole(){
return console;
}

public void startPlugin(){
PluginManager manager = getServer().getPluginManager();

getMessageUtil().sendMessage("<grey>Server marked as 'done'! Checking for ItemsAdder...");
if(!manager.isPluginEnabled("ItemsAdder")){
getMessageUtil().sendMessage("<red>ItemsAdder is not enabled! IAxPresenceFootsteps requires it to work.");
manager.disablePlugin(this);
return;
}

if(loadCommands()){
getMessageUtil().sendMessage("<green>Successfully enabled IAxPresenceFootsteps!");
}else{
manager.disablePlugin(this);
}
}

private void loadMessageUtil(){
try{
Class.forName("io.papermc.paper.text.PaperComponents");

messageUtil = new PaperMessageUtil(this);
getMessageUtil().sendMessage("<grey>Found PaperMC. Using native message system from it...");
}catch(ClassNotFoundException ex){
messageUtil = new SpigotMessageUtils(this);
getMessageUtil().sendMessage("<grey>Found SpigotMC. Using BukkitAudiences from Kyori Adventure...");
}
}

private boolean loadCommands(){
getMessageUtil().sendMessage("<grey>Loading <aqua>/pfcreate</aqua> command...");
PluginCommand pfCreate = this.getCommand("pfcreate");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ch.andre601.iaxpresencefootsteps.events;

import ch.andre601.iaxpresencefootsteps.IAxPresenceFootsteps;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent;

public class ServerEvents implements Listener{

private final IAxPresenceFootsteps plugin;

public ServerEvents(IAxPresenceFootsteps plugin){
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

// Workaround for wanky softdepend stuff: https://github.com/PaperMC/Paper/issues/5992
@EventHandler
public void onServerLoad(ServerLoadEvent event){
plugin.startPlugin();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ public class Messages{

// JsonCreator.createFiles messages
public static final String OUTDATED_ITEMSADDER = "<red>You are using an outdated version of ItemsAdder! Use at least 3.1.5.";
public static final String NO_BLOCK_CACHE = "[IAxPresenceFootsteps] <red>ItemsAdder does not have a <grey>real_blocks_note_ids_cache.yml</grey> file!";
public static final String NO_BLOCK_CACHE = "<red>ItemsAdder does not have a <grey>real_blocks_note_ids_cache.yml</grey> file!";
public static final String FILE_READ_ERROR = "<red>There was an error while reading the block cache file from ItemsAdder! Error: %s";
public static final String FILE_EMPTY = "<red>The <grey>real_blocks_note_ids_cache.yml</grey> file does not have any entries.";

public static final String NO_OVERRIDE_ALLOWED_1 = "<red>A blockmap.json file already exists! Not overriding file...";
public static final String NO_OVERRIDE_ALLOWED_2 = "<red>Use <grey>/pfcreate --override</grey> to force an override.";
public static final String NO_OVERRIDE_ALLOWED_2 =
"<red>Use <grey><click:run_command:/pfcreate --override><hover:show_text:'<grey>Click to execute command'>" +
"/pfcreate --override</hover></click></grey> to force an override.";

public static final String BLOCK_COLLECTION_START = "<grey>Collecting valid custom blocks. Check console for progress...";
public static final String BLOCK_COLLECTION_END = "<green>Collecting of custom blocks complete! Creating <grey>blockmap.json</grey>...";

public static final String BLOCKMAP_FILE_CREATED = "<green>No <grey>blockmap.json</grey> found. Creating it...";
public static final String BLOCKMAP_FILE_CREATED = "<green>No <grey>blockmap.json</grey> found. Creating new one...";
public static final String BLOCKMAP_CREATED = "<green>Successfully created <grey>blockmap.json</grey> file.";
public static final String BLOCKMAP_IAZIP_TRIGGER = "<grey>Executing <aqua>/iazip</aqua>...";
public static final String BLOCKMAP_IAZIP_REMIND = "<green>Remember to use <grey>/iazip</grey> to update the resource pack.";
public static final String BLOCKMAP_IAZIP_REMIND =
"<green>Remember to use <grey><click:run_command:/iazip><hover:show_text:'<grey>Click to execute command'>" +
"/iazip</hover></click></grey> to update the resource pack.";

public static final String BLOCKMAP_CREATION_EXCEPTION = "<red>Could not create the blockmap.json due to an IOException: %s";

// JsonCreator.getBlockmapValues messages
// JsonCreator.getBlockmapValues message
public static final String BLOCK_FOUND = "<grey>Found <aqua>%s:%s</aqua> with pf_sound configuration. Adding to blockmap.json file...";

// Command messages
Expand Down

0 comments on commit 0d9093e

Please sign in to comment.