Skip to content

Commit

Permalink
ISB 1.6 Update
Browse files Browse the repository at this point in the history
...
  • Loading branch information
piotrwyrw committed Jul 7, 2020
1 parent 9b0182a commit 1f2303b
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 10 deletions.
12 changes: 8 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ msg-stop: '&aAll update tasks have been stopped. The scoreboard won%APOSTROPHE%t
msg-start: '&aA new score board update process has just started.'
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.'

#-----------------------------------#
# S I G N S #
#-----------------------------------#

sign-format:
- ''
- '&2%NUMBER%'
- '&7%PLAYER%'
- '&c%VALUE%'
- '&3&l#%NUMBER%'
- '&8%PLAYER%'
- '&8%VALUE%'
- '&6[Right Click]'

sign-empty-format:
- ''
Expand Down
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.5
version: 1.6
author: piotrwyrw
api-version: 1.15
commands:
Expand Down
5 changes: 4 additions & 1 deletion src/org/piotrwyrw/iridiumscoreboard/IridiumScoreBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.piotrwyrw.iridiumscoreboard.commands.IridiumScoreBoardMainCommand;
import org.piotrwyrw.iridiumscoreboard.config.IridiumScoreBoardConfiguration;
import org.piotrwyrw.iridiumscoreboard.globals.Messages;
import org.piotrwyrw.iridiumscoreboard.listener.ClickableSign;
import org.piotrwyrw.iridiumscoreboard.scoreboard.ScoreBoard;
import org.piotrwyrw.iridiumscoreboard.scoreboard.ScorePanel;
import org.piotrwyrw.iridiumscoreboard.scoreboard.ScoreUpdater;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void onEnable() {
instance = this;

if (!getServer().getPluginManager().getPlugin("IridiumSkyblock").isEnabled()) {
getLogger().warning(Messages.PREFIX + "§7IridiumScoreBoard requires the IridiumSkyblock plugin to work. Install the plugin and try again.");
getLogger().warning("\n\nIridiumScoreBoard requires the IridiumSkyblock plugin to work. Install the plugin and try again.\n");
getServer().getPluginManager().disablePlugin(this);
return;
}
Expand All @@ -82,6 +83,8 @@ public void onEnable() {

getCommand("isb").setExecutor(new IridiumScoreBoardMainCommand());

getServer().getPluginManager().registerEvents(new ClickableSign(), this);

startUpdater();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return new TestPanelCommand().handleCommand(sender, args);
case "reload":
return new ReloadCommand().handleCommand(sender, args);
case "reset":
return new ResetConfig().handleCommand(sender, args);
case "help":
default:
HelpPage.show(sender);
Expand Down
30 changes: 30 additions & 0 deletions src/org/piotrwyrw/iridiumscoreboard/commands/ResetConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.piotrwyrw.iridiumscoreboard.commands;

import org.bukkit.command.CommandSender;
import org.piotrwyrw.iridiumscoreboard.IridiumScoreBoard;
import org.piotrwyrw.iridiumscoreboard.config.IridiumScoreBoardConfiguration;
import org.piotrwyrw.iridiumscoreboard.globals.Messages;
import org.piotrwyrw.iridiumscoreboard.globals.Permissions;
import org.piotrwyrw.iridiumscoreboard.scoreboard.ScoreUpdater;

public class ResetConfig extends CommandHandler {

@Override
public boolean handleCommand(CommandSender sender, String[] args) {
if (!sender.hasPermission(Permissions.RESET_CONFIG)) {
sender.sendMessage(Messages.NO_PERMISSION);
return false;
}

if (args.length != 1) {
sender.sendMessage(Messages.EXPECTED_ARGUMENTS(0));
return false;
}

sender.sendMessage(Messages.RESETTING_CONF);
IridiumScoreBoard.getInstance().saveResource("config.yml", true);
sender.sendMessage(Messages.RESET_DONE);
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class HelpPage {
"§b/isb stop §8- §eStop the update timer §c(" + Permissions.STOP_UPDATE + ")",
"§b/isb test §8- §eTest all panels §c(" + Permissions.TEST_SCORE_PANELS + ")",
"§b/isb reload §8- §eReload the config §c(" + Permissions.RELOAD_ISB + ")",
"§b/isb reset §8- §eReset the config §c(" + Permissions.RESET_CONFIG + ")",
"§8o------------------------------------------------o",
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public IridiumScoreBoardConfiguration() {

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

Expand Down Expand Up @@ -73,10 +73,26 @@ public IridiumScoreBoardConfiguration() {
Messages.CONF_RELOADING = Messages.PREFIX + Fields.specialCharacterFields(config.getString(Configs.RELOADING));
}

if (config.get(Configs.IS_PRIVATE) != null) {
Messages.IS_PRIVATE = Messages.PREFIX + Fields.specialCharacterFields(config.getString(Configs.IS_PRIVATE));
}

if (config.get(Configs.IS_WHOOSH) != null) {
Messages.IS_SB_TP = Messages.PREFIX + Fields.specialCharacterFields(config.getString(Configs.IS_WHOOSH));
}

if (config.get(Configs.RESETTING_CONF) != null) {
Messages.RESETTING_CONF = Messages.PREFIX + Fields.specialCharacterFields(config.getString(Configs.RESETTING_CONF));
}

if (config.get(Configs.RESET_DONE) != null) {
Messages.RESET_DONE = Messages.PREFIX + Fields.specialCharacterFields(config.getString(Configs.RESET_DONE));
}

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

isb.getLogger().info("---- Done reading configuration. ----");
isb.getLogger().info("\n\n---- Done reading configuration. ----\n");
}
}
4 changes: 4 additions & 0 deletions src/org/piotrwyrw/iridiumscoreboard/globals/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class Configs {
public static String SAVED = "msg-saved";
public static String RELOADING = "msg-reloading";
public static String RELOAD = "msg-reloaded";
public static String IS_PRIVATE = "msg-private";
public static String IS_WHOOSH = "msg-whoosh";
public static String RESETTING_CONF = "msg-resetting";
public static String RESET_DONE = "msg-reset-done";

public static String SIGN_FORMAT = "sign-format";
public static String EMPTY_SIGN_FORMAT = "sign-empty-format";
Expand Down
12 changes: 12 additions & 0 deletions src/org/piotrwyrw/iridiumscoreboard/globals/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public class Messages {
// Reloading
public static String CONF_RELOADING = PREFIX + "§7Reloading config ..";

// Island is private
public static String IS_PRIVATE = PREFIX + "§cThis island is private.";

// Sign tp success
public static String IS_SB_TP = PREFIX + "§aWhoosh!";

// Resetting config
public static String RESETTING_CONF = PREFIX + "§7Resetting config ..";

// Reset done
public static String RESET_DONE = PREFIX + "§aConfig reset.";

// Exception message
public static String EXCEPTION(String details) {
return PREFIX + "§4Error\n§c" + details;
Expand Down
3 changes: 3 additions & 0 deletions src/org/piotrwyrw/iridiumscoreboard/globals/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public class Permissions {

// Relaod
public static String RELOAD_ISB = "isb.reload";

// Regen config
public static String RESET_CONFIG = "isb.reset";
}
50 changes: 50 additions & 0 deletions src/org/piotrwyrw/iridiumscoreboard/listener/ClickableSign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.piotrwyrw.iridiumscoreboard.listener;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.piotrwyrw.iridiumscoreboard.IridiumScoreBoard;
import org.piotrwyrw.iridiumscoreboard.globals.Messages;
import org.piotrwyrw.iridiumscoreboard.scoreboard.ScoreBoard;
import org.piotrwyrw.iridiumscoreboard.util.LocationComparator;

import com.iridium.iridiumskyblock.Island;
import com.iridium.iridiumskyblock.Utils;

public class ClickableSign implements Listener {

@EventHandler
public void signClicked(PlayerInteractEvent evt) {

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

ScoreBoard sb = IridiumScoreBoard.getScoreBoard();
List<Island> top = Utils.getTopIslands();
int iterations = ((top.size() <= sb.count()) ? top.size() : sb.count());

for (int a = 0; a < iterations; a ++) {
Location loc = sb.scorepanels.get(a).location;
if (LocationComparator.isSame(loc, evt.getClickedBlock().getLocation())) {
for (int b = 0; b < Utils.getTopIslands().size(); b ++) {
if (a == b) {
if (!top.get(b).isVisit()) {
evt.getPlayer().sendMessage(Messages.IS_PRIVATE);
break;
}
evt.getPlayer().teleport(top.get(b).getHome());
evt.getPlayer().sendMessage(Messages.IS_SB_TP);
}
}
}
}
return;
}
}
10 changes: 10 additions & 0 deletions src/org/piotrwyrw/iridiumscoreboard/util/LocationComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.piotrwyrw.iridiumscoreboard.util;

import org.bukkit.Location;

public class LocationComparator {
public static boolean isSame(Location loc1, Location loc2) {
return ((loc1.getX() == loc2.getX()) && (loc1.getY() == loc2.getY()) && (loc1.getZ() == loc2.getZ()))
? true : false;
}
}

1 comment on commit 1f2303b

@piotrwyrw
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need a code cleanup pretty soon

Please sign in to comment.