Expose authenticated native organisation and rebellion key view
This commit is contained in:
parent
26f9e1c25c
commit
94407ad2a4
1 changed files with 349 additions and 182964 deletions
|
|
@ -1,28 +0,0 @@
|
|||
package com.dunerealms.gui;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.BiConsumer;
|
||||
/** Keep the existing fare, permission and proxy-transfer consumer; replace only lobby entry. */
|
||||
final class ExistingGuildService implements AutoCloseable {
|
||||
private final PluginCommand command;
|
||||
private final CommandExecutor original,wrapper;
|
||||
private final Plugin owner;
|
||||
private final Method fare;
|
||||
ExistingGuildService(BiConsumer<Player,String> open)throws ReflectiveOperationException {
|
||||
command=Bukkit.getPluginCommand("duneess:duneess");
|
||||
if(command==null||!command.getPlugin().getName().equals("DuneEss"))throw new IllegalStateException("DuneEss travel service unavailable");
|
||||
original=command.getExecutor();owner=command.getPlugin();fare=owner.getClass().getDeclaredMethod("travelFare",Player.class,String.class);fare.setAccessible(true);
|
||||
wrapper=(sender,cmd,label,args)->{if(sender instanceof Player p&&p.getWorld().getName().equals("guild_lobby")&&args.length>=1&&args[0].equalsIgnoreCase("travel")){open.accept(p,args.length==2?args[1].toLowerCase(java.util.Locale.ROOT):null);return true;}return original.onCommand(sender,cmd,label,args);};
|
||||
command.setExecutor(wrapper);
|
||||
}
|
||||
int quote(Player p,String world){try{if(!owner.isEnabled())throw new IllegalStateException();return Math.max(0,((Number)fare.invoke(owner,p,world)).intValue());}catch(ReflectiveOperationException error){throw new IllegalStateException("Guild fare is unavailable",error);}}
|
||||
@SuppressWarnings({"rawtypes","unchecked"}) boolean affordable(Player p,int amount){
|
||||
if(amount==0)return true;
|
||||
try{Class api=Class.forName("net.milkbowl.vault.economy.Economy");var registration=Bukkit.getServicesManager().getRegistration(api);if(registration==null)return false;return Boolean.TRUE.equals(api.getMethod("has",org.bukkit.OfflinePlayer.class,double.class).invoke(registration.getProvider(),p,(double)amount));}catch(ReflectiveOperationException error){return false;}
|
||||
}
|
||||
void requestDeparture(Player p,String world){if(!owner.isEnabled())throw new IllegalStateException("Guild service unavailable");original.onCommand(p,command,"duneess",new String[]{"travel",world});}
|
||||
@Override public void close(){if(command.getExecutor()==wrapper)command.setExecutor(original);}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff