Some fixes and cleanup

Don't require ButtonPlugin for unregistering components
Cleanup
Fixed not detecting missing player name
This commit is contained in:
Norbi Peti 2020-10-30 22:56:11 +01:00
parent 66be5ab0dc
commit 9fb35eb6cc
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
6 changed files with 7 additions and 25 deletions

View file

@ -85,7 +85,6 @@ public class MainPlugin extends ButtonPlugin {
@Override @Override
public void pluginEnable() { public void pluginEnable() {
// Logs "Plugin Enabled", registers commands
Instance = this; Instance = this;
PluginDescriptionFile pdf = getDescription(); PluginDescriptionFile pdf = getDescription();
logger = getLogger(); logger = getLogger();

View file

@ -31,12 +31,13 @@ public class PlayerListener implements Listener {
public void OnPlayerJoin(PlayerJoinEvent event) { public void OnPlayerJoin(PlayerJoinEvent event) {
var p = event.getPlayer(); var p = event.getPlayer();
TBMCPlayer player = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class); TBMCPlayer player = TBMCPlayerBase.getPlayer(p.getUniqueId(), TBMCPlayer.class);
if (player.PlayerName.get() == null) { String pname = player.PlayerName.get();
if (pname.length() == 0) {
player.PlayerName.set(p.getName()); player.PlayerName.set(p.getName());
MainPlugin.Instance.getLogger().info("Player name saved: " + player.PlayerName.get()); MainPlugin.Instance.getLogger().info("Player name saved: " + player.PlayerName.get());
} else if (!p.getName().equals(player.PlayerName.get())) { } else if (!p.getName().equals(pname)) {
TownyComponent.renameInTowny(player.PlayerName.get(), p.getName()); TownyComponent.renameInTowny(pname, p.getName());
MainPlugin.Instance.getLogger().info(player.PlayerName.get() + " renamed to " + p.getName()); MainPlugin.Instance.getLogger().info(pname + " renamed to " + p.getName());
player.PlayerName.set(p.getName()); player.PlayerName.set(p.getName());
} }
} }
@ -69,10 +70,6 @@ public class PlayerListener implements Listener {
private void handlePreprocess(CommandSender sender, String message, Cancellable event) { private void handlePreprocess(CommandSender sender, String message, Cancellable event) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
/*val cg = Optional.ofNullable(ChromaGamerBase.getFromSender(sender));
val ch = cg.map(ChromaGamerBase::channel).map(ChannelPlayerData::get);
val rtr = ch.map(c -> c.getRTR(sender)).orElseGet(() -> new Channel.RecipientTestResult("Failed to get user"));
val ev = new TBMCCommandPreprocessEvent(sender, ch.orElse(Channel.GlobalChat), message, rtr.score, rtr.groupID);*/
val cg = ChromaGamerBase.getFromSender(sender); val cg = ChromaGamerBase.getFromSender(sender);
if (cg == null) throw new RuntimeException("Couldn't get user from sender for " + sender.getName() + "!"); if (cg == null) throw new RuntimeException("Couldn't get user from sender for " + sender.getName() + "!");
val ev = new TBMCCommandPreprocessEvent(sender, cg.channel.get(), message, sender); val ev = new TBMCCommandPreprocessEvent(sender, cg.channel.get(), message, sender);

View file

@ -57,19 +57,13 @@ public class RestartComponent extends Component<MainPlugin> implements Listener
private int syncStart(int hour) { private int syncStart(int hour) {
var now = ZonedDateTime.now(ZoneId.ofOffset("", ZoneOffset.UTC)); var now = ZonedDateTime.now(ZoneId.ofOffset("", ZoneOffset.UTC));
int secs = now.getHour() * 3600 + now.getMinute() * 60 + now.getSecond(); int secs = now.getHour() * 3600 + now.getMinute() * 60 + now.getSecond();
//System.out.println("now: " + secs / 3600.);
int diff = secs - hour * 3600; int diff = secs - hour * 3600;
//System.out.println("diff: " + diff / 3600.);
if (diff < 0) { if (diff < 0) {
diff += 24 * 3600; diff += 24 * 3600;
} }
//System.out.println("diff: " + diff / 3600.);
int count = diff / (24 * 3600); int count = diff / (24 * 3600);
//System.out.println("count: " + count);
int intervalPart = diff - count * 24 * 3600; int intervalPart = diff - count * 24 * 3600;
//System.out.println("intervalPart: " + intervalPart / 3600.);
int remaining = 24 * 3600 - intervalPart; int remaining = 24 * 3600 - intervalPart;
//System.out.println("remaining: " + remaining / 3600.);
return remaining * 20; return remaining * 20;
} }

View file

@ -58,7 +58,7 @@ public abstract class Component<TP extends JavaPlugin> {
* @param component The component to unregister * @param component The component to unregister
* @return Whether the component is unregistered successfully (it also got disabled) * @return Whether the component is unregistered successfully (it also got disabled)
*/ */
public static <T extends ButtonPlugin> boolean unregisterComponent(T plugin, Component<T> component) { public static <T extends JavaPlugin> boolean unregisterComponent(T plugin, Component<T> component) {
return registerUnregisterComponent(plugin, component, false); return registerUnregisterComponent(plugin, component, false);
} }

View file

@ -119,7 +119,7 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
protected final HashMap<String, SubcommandData<TC>> subcommands = new HashMap<>(); protected final HashMap<String, SubcommandData<TC>> subcommands = new HashMap<>();
protected final HashMap<Class<?>, ParamConverter<?>> paramConverters = new HashMap<>(); protected final HashMap<Class<?>, ParamConverter<?>> paramConverters = new HashMap<>();
private ArrayList<String> commandHelp = new ArrayList<>(); //Mainly needed by Discord private final ArrayList<String> commandHelp = new ArrayList<>(); //Mainly needed by Discord
private char commandChar; private char commandChar;

View file

@ -193,11 +193,6 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
int i = commandline.indexOf(' '); int i = commandline.indexOf(' ');
String mainpath = commandline.substring(1, i == -1 ? commandline.length() : i); //Without the slash String mainpath = commandline.substring(1, i == -1 ? commandline.length() : i); //Without the slash
PluginCommand pcmd; PluginCommand pcmd;
/*System.out.println("Command line: " + commandline);
System.out.println("Prioritize: " + MainPlugin.Instance.prioritizeCustomCommands().get());
System.out.println("PCMD: " + (pcmd = Bukkit.getPluginCommand(mainpath)));
if (pcmd != null)
System.out.println("ButtonPlugin: " + (pcmd.getPlugin() instanceof ButtonPlugin));*/
if (!checkPlugin if (!checkPlugin
|| MainPlugin.Instance.prioritizeCustomCommands.get() || MainPlugin.Instance.prioritizeCustomCommands.get()
|| (pcmd = Bukkit.getPluginCommand(mainpath)) == null //Our commands aren't PluginCommands || (pcmd = Bukkit.getPluginCommand(mainpath)) == null //Our commands aren't PluginCommands
@ -249,7 +244,6 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
sender.sendMessage("§cAn internal error occurred."); sender.sendMessage("§cAn internal error occurred.");
return true; return true;
} }
//System.out.println("Executing " + label + " which is actually " + command.getName());
handleCommand(new Command2MCSender(sender, user.channel.get(), sender), handleCommand(new Command2MCSender(sender, user.channel.get(), sender),
("/" + command.getName() + " " + String.join(" ", args)).trim(), false); ///trim(): remove space if there are no args ("/" + command.getName() + " " + String.join(" ", args)).trim(), false); ///trim(): remove space if there are no args
return true; return true;
@ -267,13 +261,11 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
@Override @Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
//System.out.println("Correct tabcomplete queried");
return Collections.emptyList(); return Collections.emptyList();
} }
@Override @Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException { public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
//System.out.println("Correct tabcomplete queried");
return Collections.emptyList(); return Collections.emptyList();
} }
} }