Skip to content

Commit

Permalink
Bugfix & Stuff (ISB 1.7)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwyrw committed Jul 11, 2020
1 parent 1671d98 commit 16996da
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 43 deletions.
18 changes: 7 additions & 11 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# %COPY% - Copyright (whoever needs it)
# %PARAGRAPH% - A paragraph character
# %APOSTROPHE% - An apostrophe
#
# Look at config for examples of using fields.

# If you would need to use an apostrophe inside of a message / sign format,
# use %APOSTROPHE% instead. In case you will use ' instead of apostrophe field,
Expand All @@ -33,7 +31,7 @@
# M E S S A G E S #
#-----------------------------------#

msg-prefix: '&b&lIridiumScoreBoard&8 %RAQUO%&r '
msg-prefix: '&b&lIridiumScoreBoard&8 %LAQUO%&r '
msg-no-permission: '&cYou don%APOSTROPHE%t have permission to do that.'
msg-no-console: '&cYou must be a player to execute this command.'
msg-panel-add: '&aThe score panel was added to the list.'
Expand All @@ -47,7 +45,6 @@ msg-saved: '&aSaved.'
msg-reloaded: '&aConfig reloaded.'
msg-private: '&cThis island is private.'
msg-whoosh: '&aWhoosh!'
msg-resetting: '&7Resetting config ..'
msg-reset-done: '&aConfig reset.'

#-----------------------------------#
Expand All @@ -56,19 +53,18 @@ msg-reset-done: '&aConfig reset.'

sign-format:
- ''
- '&3&l#%NUMBER%'
- '&2&lTOP %NUMBER%'
- '&7%PLAYER%'
- '&c%VALUE%'
- '&a%VALUE%'

sign-empty-format:
- ''
- '&7No data'
- '&3&l%LAQUO%%RAQUO%'
- ''
- ''
- ''

#-----------------------------------#
# P E R M I S S I O N #
# P E R M I S S I O N S #
#-----------------------------------#

# Comming soon

signtp-bypasspermission: true
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: IridiumScoreBoard
main: org.piotrwyrw.iridiumscoreboard.IridiumScoreBoard
depend: [IridiumSkyblock]
version: 1.6
version: 1.7
author: piotrwyrw
api-version: 1.15
commands:
Expand Down
3 changes: 2 additions & 1 deletion src/org/piotrwyrw/iridiumscoreboard/IridiumScoreBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public static void startUpdater() {
public void onEnable() {

if (!getServer().getPluginManager().getPlugin("IridiumSkyblock").isEnabled()) {
getLogger().warning("\n\nIridiumScoreBoard requires the IridiumSkyblock plugin to work. Install the plugin and try again.\n");
for (String line : Texts.no_dependency)
getLogger().warning(line);
getServer().getPluginManager().disablePlugin(this);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean handleCommand(CommandSender sender, String[] args) {
return false;
}

if (!sender.hasPermission(Permissions.COMMAND_ADD)) {
if (!Permissions.has(sender, Permissions.COMMAND_ADD)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ClearCommand extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.COMMAND_CLEAR)) {
if (!Permissions.has(sender, Permissions.COMMAND_CLEAR)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.piotrwyrw.iridiumscoreboard.IridiumScoreBoard;
import org.piotrwyrw.iridiumscoreboard.global.Texts;

public class MainCommand implements CommandExecutor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ReloadCommand extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.COMMAND_RELOAD)) {
if (!Permissions.has(sender, Permissions.COMMAND_RELOAD)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand All @@ -21,7 +21,6 @@ public boolean handleCommand(CommandSender sender, String[] args) {
return false;
}

sender.sendMessage(Messages.RELOADING);
IridiumScoreBoard.getInstance().reloadConfig();
Configuration.readConfig();
ScoreUpdater updater = new ScoreUpdater(IridiumScoreBoard.getScoreBoard());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ResetCommand extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.COMMAND_RESET)) {
if (!Permissions.has(sender, Permissions.COMMAND_RESET)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand All @@ -21,7 +21,6 @@ public boolean handleCommand(CommandSender sender, String[] args) {
return false;
}

sender.sendMessage(Messages.RESETTING_CONFIGURATION);
IridiumScoreBoard.getInstance().saveResource("config.yml", true);
sender.sendMessage(Messages.DONE_RESETTING);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SaveCommand extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.COMMAND_SAVE)) {
if (!Permissions.has(sender, Permissions.COMMAND_SAVE)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class StartCommand extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.COMMAND_START)) {
if (!Permissions.has(sender, Permissions.COMMAND_START)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class StopCommand extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.COMMAND_STOP)) {
if (!Permissions.has(sender, Permissions.COMMAND_STOP)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/piotrwyrw/iridiumscoreboard/commands/TestCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestCommand extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.COMMAND_TEST)) {
if (!Permissions.has(sender, Permissions.COMMAND_TEST)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}
Expand All @@ -30,7 +30,7 @@ public boolean handleCommand(CommandSender sender, String[] args) {
return false;
}

IridiumScoreBoard.getScoreBoard().test();
IridiumScoreBoard.getScoreBoard().test(sender);
sender.sendMessage(Messages.DONE_TESTING);
return true;
}
Expand Down
21 changes: 12 additions & 9 deletions src/org/piotrwyrw/iridiumscoreboard/config/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package org.piotrwyrw.iridiumscoreboard.config;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.bukkit.configuration.file.FileConfiguration;
import org.piotrwyrw.iridiumscoreboard.IridiumScoreBoard;
import org.piotrwyrw.iridiumscoreboard.global.ConfigPath;
import org.piotrwyrw.iridiumscoreboard.global.Messages;
import org.piotrwyrw.iridiumscoreboard.global.Permissions;
import org.piotrwyrw.iridiumscoreboard.global.SignFormats;
import org.piotrwyrw.iridiumscoreboard.util.Utilities;

public class Configuration {
public static void readConfig() {
IridiumScoreBoard isb = IridiumScoreBoard.getInstance();
FileConfiguration config = isb.getConfig();

File configFile = new File(isb.getDataFolder(), "config.yml");
if (!configFile.exists()) {
isb.getLogger().info("\n\n---- Creating configuration file .. ----\n");
isb.getLogger().info("---- Creating configuration file .. ----");
isb.saveResource("config.yml", true);
}

Expand Down Expand Up @@ -81,18 +84,14 @@ public static void readConfig() {
Messages.ISLAND_TELEPORT = Messages.PREFIX + Utilities.specialCharacterFields(config.getString(ConfigPath.ISLAND_TELEPORT));
}

if (config.get(ConfigPath.RESETTING_CONFIGURATION) != null) {
Messages.RESETTING_CONFIGURATION = Messages.PREFIX + Utilities.specialCharacterFields(config.getString(ConfigPath.RESETTING_CONFIGURATION));
}

if (config.get(ConfigPath.DONE_RESETTING) != null) {
Messages.DONE_RESETTING = Messages.PREFIX + Utilities.specialCharacterFields(config.getString(ConfigPath.DONE_RESETTING));
}

if (config.get(ConfigPath.SIGN_FORMAT) != null) {
List<String> format = config.getStringList(ConfigPath.SIGN_FORMAT);
if (format.size() != 4) {
isb.getLogger().warning("\n\n---- Expected 4 lines of sign formatting but got " + format.size() + " ----\n");
isb.getLogger().warning("---- Expected 4 lines of sign formatting but got " + format.size() + " ----");
} else {
SignFormats.sign_format.clear();
for (String str : format)
Expand All @@ -103,14 +102,18 @@ public static void readConfig() {
if (config.get(ConfigPath.EMPTY_SIGN_FORMAT) != null) {
List<String> format = config.getStringList(ConfigPath.EMPTY_SIGN_FORMAT);
if (format.size() != 4) {
isb.getLogger().warning("\n\n---- Expected 4 lines of empty sign formatting but got " + format.size() + " ----\n");
isb.getLogger().warning("---- Expected 4 lines of empty sign formatting but got " + format.size() + " ----");
} else {
SignFormats.empty.clear();
for (String str : format)
SignFormats.empty.add(str.replaceAll("\\&", "§"));
}
}

isb.getLogger().info("\n\n---- Done reading configuration. ----\n");
if (config.get(ConfigPath.SIGNTELEPORT_REQUIRE_PERMISSION) != null) {
Permissions.EVENT_SIGNTELEPORT_REQUIRE = !config.getBoolean(ConfigPath.SIGNTELEPORT_REQUIRE_PERMISSION);
}

isb.getLogger().info("---- Done reading configuration. ----");
}
}
3 changes: 2 additions & 1 deletion src/org/piotrwyrw/iridiumscoreboard/global/ConfigPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class ConfigPath {
public static String RELOAD_COMPLETE = "msg-reloaded";
public static String ISLAND_IS_PRIVATE = "msg-private";
public static String ISLAND_TELEPORT = "msg-whoosh";
public static String RESETTING_CONFIGURATION = "msg-resetting";
public static String DONE_RESETTING = "msg-reset-done";

public static String SIGN_FORMAT = "sign-format";
public static String EMPTY_SIGN_FORMAT = "sign-empty-format";

public static String SIGNTELEPORT_REQUIRE_PERMISSION = "signtp-bypasspermission";
}
1 change: 0 additions & 1 deletion src/org/piotrwyrw/iridiumscoreboard/global/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class Messages {
public static String RELOADING = PREFIX + "§7Reloading config ..";
public static String ISLAND_IS_PRIVATE = PREFIX + "§cThis island is private.";
public static String ISLAND_TELEPORT = PREFIX + "§aWhoosh!";
public static String RESETTING_CONFIGURATION = PREFIX + "§7Resetting config ..";
public static String DONE_RESETTING = PREFIX + "§aConfig reset.";

public static String EXCEPTION(String details) {
Expand Down
17 changes: 16 additions & 1 deletion src/org/piotrwyrw/iridiumscoreboard/global/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@
import java.util.List;
import java.util.UUID;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Permissions {
public static List<UUID> bypass = new ArrayList<UUID>();
//public static List<UUID> admins = new ArrayList<UUID>();

public static boolean has(CommandSender sender, String permission) {
if (!(sender instanceof Player)) return true;

Player p = ((Player)sender);
if (p.hasPermission(permission));
return true;
}

public static String COMMAND_ADD = "isb.add";
public static String COMMAND_CLEAR = "isb.clear";
public static String COMMAND_STOP = "isb.stop";
Expand All @@ -14,4 +26,7 @@ public class Permissions {
public static String COMMAND_SAVE = "isb.save";
public static String COMMAND_RELOAD = "isb.reload";
public static String COMMAND_RESET = "isb.reset";

public static boolean EVENT_SIGNTELEPORT_REQUIRE = true;
public static String EVENT_SIGNTELEPORT = "isb.signtp";
}
11 changes: 11 additions & 0 deletions src/org/piotrwyrw/iridiumscoreboard/global/Texts.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ public class Texts {
"",
"- - - - - - - - - - - - - - - -"
};

public static String[] no_dependency = {
"- - - - - - - - - - - - - - - - - -",
"",
" IRIDIUM SCORE BOARD ",
" This plugin needs IridiumSkyBlock",
"to work. Please install this plugin",
" and try again.",
"",
"- - - - - - - - - - - - - - - - - -"
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.piotrwyrw.iridiumscoreboard.IridiumScoreBoard;
import org.piotrwyrw.iridiumscoreboard.global.Messages;
import org.piotrwyrw.iridiumscoreboard.global.Permissions;
import org.piotrwyrw.iridiumscoreboard.scoreboard.ScoreBoard;
import org.piotrwyrw.iridiumscoreboard.util.Utilities;

Expand All @@ -22,9 +23,11 @@ public class ClickableSign implements Listener {
@EventHandler
public void signClicked(PlayerInteractEvent evt) {

if (evt.getAction() != Action.RIGHT_CLICK_BLOCK || !(evt.getClickedBlock().getState() instanceof Sign)) {
if (evt.getAction() != Action.RIGHT_CLICK_BLOCK || !(evt.getClickedBlock().getState() instanceof Sign))
return;

if (evt.getPlayer().hasPermission(Permissions.EVENT_SIGNTELEPORT) && Permissions.EVENT_SIGNTELEPORT_REQUIRE)
return;
}

ScoreBoard sb = IridiumScoreBoard.getScoreBoard();
List<Island> top = Utils.getTopIslands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Sign;
import org.bukkit.command.CommandSender;
import org.piotrwyrw.iridiumscoreboard.IridiumScoreBoard;
import org.piotrwyrw.iridiumscoreboard.global.Messages;

Expand All @@ -16,7 +17,7 @@ public ScoreBoard() {
this.scorepanels = new ArrayList<ScorePanel>();
}

public void test() {
public void test(CommandSender sender) {
if (scorepanels == null) return;
if (scorepanels.size() <= 0) return;

Expand All @@ -25,8 +26,8 @@ public void test() {
for (int i = 0; i < scorepanels.size(); i ++) {
ScorePanel p = scorepanels.get(i);
if (!(p.location.getBlock().getState() instanceof Sign)) {
Bukkit.broadcastMessage(Messages.ENCOUNTERED_WRONG_BLOCK);
isb.getLogger().warning("\n\n----- WARNING: " + p.location.getX() + ", " + p.location.getY() + ", " + p.location.getZ() + " should be a sign, but the block is of type " + p.location.getBlock().getType().toString() + " -----\n");
sender.sendMessage(Messages.ENCOUNTERED_WRONG_BLOCK);
isb.getLogger().warning("----- WARNING: " + p.location.getX() + ", " + p.location.getY() + ", " + p.location.getZ() + " should be a sign, but the block is of type " + p.location.getBlock().getType().toString() + " -----");
continue;
}
p.test();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.command.CommandSender;
import org.piotrwyrw.iridiumscoreboard.global.SignFormats;
import org.piotrwyrw.iridiumscoreboard.util.Utilities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.piotrwyrw.iridiumscoreboard.global.SignFormats;
Expand Down Expand Up @@ -37,7 +38,7 @@ public void run() {
Player player = Bukkit.getPlayer(UUID.fromString(top.get(i).getOwner()));

if (player != null) {
ownerStr = player.getDisplayName();
ownerStr = ((CraftPlayer)player).getHandle().getDisplayName().getText();
} else {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(top.get(i).getOwner()));
if (offlinePlayer == null) continue;
Expand Down
Loading

0 comments on commit 16996da

Please sign in to comment.