Removed useless/abandoned Modules, AdminNotes and Scoreboard Project
Manager.
This commit is contained in:
@@ -1,216 +0,0 @@
|
||||
package com.redstoner.modules.adminnotes;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.json.simple.JSONArray;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
import com.redstoner.annotations.AutoRegisterListener;
|
||||
import com.redstoner.annotations.Commands;
|
||||
import com.redstoner.annotations.Version;
|
||||
import com.redstoner.misc.CommandHolderType;
|
||||
import com.redstoner.misc.JsonManager;
|
||||
import com.redstoner.misc.Main;
|
||||
import com.redstoner.modules.Module;
|
||||
|
||||
import de.pepich.chestapi.CallbackHandler;
|
||||
import de.pepich.chestapi.ClickableInventory;
|
||||
import de.pepich.chestapi.DefaultSize;
|
||||
import net.nemez.chatapi.click.ClickCallback;
|
||||
import net.nemez.chatapi.click.Message;
|
||||
|
||||
@Commands(CommandHolderType.String)
|
||||
@AutoRegisterListener
|
||||
@Version(major = 4, minor = 0, revision = 0, compatible = 4)
|
||||
public class AdminNotes implements Module, Listener
|
||||
{
|
||||
JSONArray notes;
|
||||
File saveFile = new File(Main.plugin.getDataFolder(), "adminnotes.json");
|
||||
|
||||
@Override
|
||||
public boolean onEnable()
|
||||
{
|
||||
notes = JsonManager.getArray(saveFile);
|
||||
if (notes == null)
|
||||
notes = new JSONArray();
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e)
|
||||
{
|
||||
if (e.getPlayer().hasPermission("utils.adminnotes"))
|
||||
if (notes.size() > 0)
|
||||
{
|
||||
Message m = new Message(e.getPlayer(), null);
|
||||
m.appendSendChat(getLogger().getPrefix(), "/an list");
|
||||
m.appendSendChat("&cThere are " + notes.size() + " open notes!", "/an list");
|
||||
m.send();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
saveNotes();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Command(hook = "an_create")
|
||||
public void createNote(CommandSender sender, String note)
|
||||
{
|
||||
JSONArray temp = new JSONArray();
|
||||
temp.add(sender.getName());
|
||||
temp.add(note);
|
||||
temp.add((double) System.currentTimeMillis() / 1000);
|
||||
notes.add(temp);
|
||||
getLogger().message(sender, "&aNote added!");
|
||||
saveNotes();
|
||||
}
|
||||
|
||||
@Command(hook = "an_del")
|
||||
public void delNote(CommandSender sender, int id)
|
||||
{
|
||||
if (id < notes.size() && id >= 0 && notes.get(id) != null)
|
||||
{
|
||||
notes.remove(id);
|
||||
getLogger().message(sender, "&aNote " + id + " has been removed!");
|
||||
saveNotes();
|
||||
}
|
||||
else
|
||||
{
|
||||
getLogger().message(sender, "&cThat note does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
@Command(hook = "an_list")
|
||||
public void list(CommandSender sender)
|
||||
{
|
||||
Message m = new Message(sender, null);
|
||||
m.appendText(getLogger().getHeader());
|
||||
for (Object note : notes)
|
||||
{
|
||||
String string = ChatColor.YELLOW + "" + notes.indexOf(note) + ": ";
|
||||
string += "§a" + ((JSONArray) note).get(1);
|
||||
string += "\n§e - " + ((JSONArray) note).get(0) + ", §6";
|
||||
SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy HH:mm");
|
||||
string += format.format((double) ((JSONArray) note).get(2) * 1000);
|
||||
m.appendCallbackHover(string, new ClickCallback(true, true, null)
|
||||
{
|
||||
@Override
|
||||
public void run(CommandSender sender)
|
||||
{
|
||||
if (notes.contains(note))
|
||||
showMenu((Player) sender, notes.indexOf(note));
|
||||
else
|
||||
getLogger().message(sender, true, "That note no longer exists!");
|
||||
}
|
||||
}, "Click to show note options.");
|
||||
m.appendText("\n");
|
||||
}
|
||||
m.send();
|
||||
}
|
||||
|
||||
public void showMenu(Player player, int index)
|
||||
{
|
||||
String note_text = ((String) ((JSONArray) notes.get(index)).get(1));
|
||||
if (note_text.length() > 15)
|
||||
note_text = note_text.substring(0, 15) + "...";
|
||||
ClickableInventory inv = new ClickableInventory("Note " + index + ": " + note_text, DefaultSize.FINAL_FIXED(9));
|
||||
|
||||
ItemStack addItem = new ItemStack(Material.BOOK_AND_QUILL);
|
||||
ItemMeta addMeta = addItem.getItemMeta();
|
||||
addMeta.setDisplayName("§aAdd note!");
|
||||
addItem.setItemMeta(addMeta);
|
||||
inv.set(1, addItem, new CallbackHandler()
|
||||
{
|
||||
@Override
|
||||
public void run(Player player, ClickType type)
|
||||
{
|
||||
Message m = new Message(player, null);
|
||||
m.appendSuggest(getLogger().getPrefix(), "/an add ");
|
||||
m.appendSuggest("Click me to add a note!", "/an add ");
|
||||
m.send();
|
||||
player.closeInventory();
|
||||
}
|
||||
});
|
||||
|
||||
ItemStack deleteItem = new ItemStack(Material.WOOL, 1, (short) 14);
|
||||
ItemMeta deleteMeta = deleteItem.getItemMeta();
|
||||
deleteMeta.setDisplayName("§cDelete note!");
|
||||
deleteMeta.setLore(Arrays.asList(new String[] {"Shift click to execute!"}));
|
||||
deleteItem.setItemMeta(deleteMeta);
|
||||
inv.set(3, deleteItem, new CallbackHandler()
|
||||
{
|
||||
@Override
|
||||
public void run(Player player, ClickType type)
|
||||
{
|
||||
if (type == ClickType.SHIFT_LEFT)
|
||||
{
|
||||
delNote(player, index);
|
||||
player.closeInventory();
|
||||
}
|
||||
else
|
||||
getLogger().message(player, true, "You need to shift click to execute this!");
|
||||
}
|
||||
});
|
||||
|
||||
ItemStack closeItem = new ItemStack(Material.BARRIER);
|
||||
ItemMeta closeMeta = closeItem.getItemMeta();
|
||||
closeMeta.setDisplayName("§eClose menu");
|
||||
closeItem.setItemMeta(closeMeta);
|
||||
inv.set(9, closeItem, new CallbackHandler()
|
||||
{
|
||||
@Override
|
||||
public void run(Player player, ClickType type)
|
||||
{
|
||||
player.closeInventory();
|
||||
}
|
||||
});
|
||||
inv.show(player);
|
||||
}
|
||||
|
||||
public void saveNotes()
|
||||
{
|
||||
JsonManager.save(notes, saveFile);
|
||||
}
|
||||
|
||||
// @noformat
|
||||
@Override
|
||||
public String getCommandString()
|
||||
{
|
||||
return "command an {\n" +
|
||||
" \n" +
|
||||
" add [string:note...] {\n" +
|
||||
" help Creates a new admin note;\n" +
|
||||
" run an_create note;\n" +
|
||||
" perm utils.an;" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
" del [int:id] {\n" +
|
||||
" help Deletes an admin note;\n" +
|
||||
" run an_del id;\n" +
|
||||
" perm utils.an;" +
|
||||
" }\n" +
|
||||
" \n" +
|
||||
" list {\n" +
|
||||
" help Lists all notes;\n" +
|
||||
" run an_list;\n" +
|
||||
" perm utils.an;" +
|
||||
" }\n" +
|
||||
"}";
|
||||
}
|
||||
// @format
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
package com.redstoner.modules.scoreboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.redstoner.misc.JsonManager;
|
||||
import com.redstoner.misc.Main;
|
||||
import com.redstoner.misc.Utils;
|
||||
|
||||
public class Project
|
||||
{
|
||||
private int progress;
|
||||
private Project parent;
|
||||
private final String projectID;
|
||||
private String projectName;
|
||||
private String displayName;
|
||||
private UUID owner;
|
||||
private JSONArray admins, members;
|
||||
private int localID;
|
||||
private Location location;
|
||||
private Scoreboard scoreboard;
|
||||
ArrayList<Project> subs = new ArrayList<Project>();
|
||||
|
||||
private Project(String projectID, Project parent, String name, String displayName, UUID owner, int localID,
|
||||
Location location, JSONArray admins, JSONArray members)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.projectID = projectID;
|
||||
this.progress = 0;
|
||||
this.owner = owner;
|
||||
this.location = location;
|
||||
this.projectName = name;
|
||||
this.localID = localID;
|
||||
this.displayName = displayName;
|
||||
this.admins = admins;
|
||||
this.members = members;
|
||||
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
updateScoreboard();
|
||||
}
|
||||
|
||||
private Project(String projectID, Project parent, String name, String displayName, UUID owner, int localID,
|
||||
Location location)
|
||||
{
|
||||
this(projectID, null, name, displayName, owner, localID, location, new JSONArray(), new JSONArray());
|
||||
}
|
||||
|
||||
private Project(Project parent, String name, String displayName, UUID owner, int localID, Location location)
|
||||
{
|
||||
this(ProjectManager.getNextID(name), null, name, displayName, owner, localID, location);
|
||||
}
|
||||
|
||||
public Project(String name, String displayName, UUID owner, int localID, Location location)
|
||||
{
|
||||
this(null, name, displayName, owner, localID, location);
|
||||
}
|
||||
|
||||
/** This method returns the progress of this project.
|
||||
*
|
||||
* @return the progress in percent, as an integer between 0 and 100 (inclusive). */
|
||||
public int getProgress()
|
||||
{
|
||||
return progress;
|
||||
}
|
||||
|
||||
/** This method sets the progress to the given parameter. The value must be between 0 and 100 (inclusive).</br>
|
||||
* If this project is not a leaf, then only 0 and 100 can be set, recursively overriding the progress of all sub-projects.</br>
|
||||
* This method will invoke updateProgress().
|
||||
*
|
||||
* @param sender The CommandSender responsible for updating the progress.
|
||||
* @param progress the new progress, 0 ≤ progress ≤ 100. */
|
||||
public void setProgress(CommandSender sender, int progress)
|
||||
{
|
||||
if (progress < 0 || progress > 100)
|
||||
{
|
||||
if (sender != null)
|
||||
Utils.sendErrorMessage(sender, null, "Progress must be between 0% and 100%!");
|
||||
return;
|
||||
}
|
||||
if (subs.size() == 0)
|
||||
{
|
||||
if (sender != null)
|
||||
Utils.sendMessage(sender, null, "Updated the project's progress to &e" + progress + "%&7.", '&');
|
||||
this.progress = progress;
|
||||
updateProgress();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (progress == 100)
|
||||
{
|
||||
for (Project project : subs)
|
||||
{
|
||||
project.setProgress(sender, progress);
|
||||
}
|
||||
updateProgress();
|
||||
if (sender != null)
|
||||
Utils.sendMessage(sender, null, "Set the entire branch to done!");
|
||||
}
|
||||
if (progress == 0)
|
||||
{
|
||||
for (Project project : subs)
|
||||
{
|
||||
project.setProgress(null, progress);
|
||||
}
|
||||
updateProgress();
|
||||
if (sender != null)
|
||||
Utils.sendMessage(sender, null, "Set the entire branch to not done!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sender != null)
|
||||
{
|
||||
Utils.sendErrorMessage(sender, null,
|
||||
"Can not set progress of a non-end project node to anything but 100 or 0!");
|
||||
Utils.sendErrorMessage(sender, null, "Please update the corresponding sub-project!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** This method updates the progress on the project, calculating it from the sub-projects if exists and updating the parent as well.</br>
|
||||
* This will also update the scoreboard. */
|
||||
public void updateProgress()
|
||||
{
|
||||
if (subs.size() != 0)
|
||||
{}
|
||||
if (parent != null)
|
||||
{
|
||||
parent.updateProgress();
|
||||
}
|
||||
updateScoreboard();
|
||||
}
|
||||
|
||||
/** This returns the unique project identifier of this project, consisting of [name]#[ID].
|
||||
*
|
||||
* @return the unique identifier. */
|
||||
public String getUUID()
|
||||
{
|
||||
return projectID;
|
||||
}
|
||||
|
||||
/** This method allows access to the parent project.
|
||||
*
|
||||
* @return the parent project, or null if this is the root project. */
|
||||
public Project getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
/** Teleports a player to the location assigned with this project. If no location can be found, the parent project's location will be used.</br>
|
||||
* If at the root Project no valid location was found, the player will not be teleported and an error message will be sent.
|
||||
*
|
||||
* @param player the player to be teleported.
|
||||
* @return true if the teleport was successfull. */
|
||||
public boolean tp(Player player)
|
||||
{
|
||||
if (location == null)
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
return parent.tp(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.getUniqueId().equals(owner))
|
||||
Utils.sendErrorMessage(player, null,
|
||||
"No location was assigned with this project! Use &e/project option location set &7(or one of the interactive menus )to define a location!");
|
||||
else
|
||||
Utils.sendErrorMessage(player, null,
|
||||
"No location was assigned with this project! Ask a project administrator to define one!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.teleport(location);
|
||||
Utils.sendMessage(player, null, "Teleported you to the projects location!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** This method converts a JSONObject representation of a Project back into the original project.</br>
|
||||
* It will also load all sub-projects recursively, and load complex types back from Strings.
|
||||
*
|
||||
* @param project The JSONObject containing the Project.
|
||||
* @return the project that was represented by the JSONObject. */
|
||||
public static Project getProject(JSONObject project)
|
||||
{
|
||||
ArrayList<Project> subs = new ArrayList<Project>();
|
||||
for (Object obj : (JSONArray) project.get("subs"))
|
||||
{
|
||||
subs.add(Project.getProject((JSONObject) obj));
|
||||
}
|
||||
String projectName = (String) project.get("projectName");
|
||||
String displayName = (String) project.get("displayName");
|
||||
String projectID = (String) project.get("projectID");
|
||||
UUID owner = UUID.fromString((String) project.get("owner"));
|
||||
JSONArray admins = (JSONArray) project.get("admins");
|
||||
JSONArray members = (JSONArray) project.get("members");
|
||||
int localID = (int) project.get("localID");
|
||||
int progress = (int) project.get("progress");
|
||||
Location location = getStringLocation((String) project.get("location"));
|
||||
Project result = new Project(projectID, null, projectName, displayName, owner, localID, location, admins,
|
||||
members);
|
||||
for (Project sub : subs)
|
||||
sub.parent = result;
|
||||
result.progress = progress;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** This method turns the project into a JSONObject for storing on the file system. It will recursively turn all sub-projects into JSONObjects</br>
|
||||
* and it will also convert all complex types into Strings.
|
||||
*
|
||||
* @return A JSONObject representing the project. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public JSONObject toJSONObject()
|
||||
{
|
||||
JSONObject project = new JSONObject();
|
||||
JSONArray subProjects = new JSONArray();
|
||||
for (Project subProject : subs)
|
||||
{
|
||||
subProjects.add(subProject.toJSONObject());
|
||||
}
|
||||
project.put("subs", subProjects);
|
||||
project.put("projectName", this.projectName);
|
||||
project.put("displayName", this.displayName);
|
||||
project.put("projectID", this.projectID);
|
||||
project.put("owner", owner.toString());
|
||||
project.put("admins", admins);
|
||||
project.put("members", members);
|
||||
project.put("localID", localID);
|
||||
project.put("progress", progress);
|
||||
project.put("parent", parent.toString());
|
||||
project.put("location", getLocationString(location));
|
||||
return project;
|
||||
}
|
||||
|
||||
/** This method converts a location into a String representation ready for storing on the file system.
|
||||
*
|
||||
* @param location The location to be turned into a String.
|
||||
* @return The String representation of the location. */
|
||||
public static String getLocationString(Location location)
|
||||
{
|
||||
UUID worldID = location.getWorld().getUID();
|
||||
return worldID + ";" + location.getX() + ";" + location.getY() + ";" + location.getZ() + ";" + location.getYaw()
|
||||
+ ";" + location.getPitch();
|
||||
}
|
||||
|
||||
/** This method converts a String representation of a location back into its original location.
|
||||
*
|
||||
* @param location The String representation of the location.
|
||||
* @return the location described by the String given, or null if the world containing it is gone.
|
||||
* @throws NumberFormatException when the floats given as coordinates are invalid.
|
||||
* @throws NumberFormatException when the UUID given as world descriptor is invalid. */
|
||||
public static Location getStringLocation(String location) throws NumberFormatException, IllegalArgumentException
|
||||
{
|
||||
String[] params = location.split(";");
|
||||
return new Location(Bukkit.getWorld(UUID.fromString(params[0])), Float.parseFloat(params[1]),
|
||||
Float.parseFloat(params[2]), Float.parseFloat(params[3]), Float.parseFloat(params[4]),
|
||||
Float.parseFloat(params[5]));
|
||||
}
|
||||
|
||||
/** This method refreshes the scoreboard assigned with the project and will be called internally when any value changes.</br>
|
||||
* You can call this method at any time before displaying the scoreboard to make sure that the displayed values are accurate. */
|
||||
public void updateScoreboard()
|
||||
{
|
||||
Objective project = scoreboard.registerNewObjective("Project", "dummy");
|
||||
project.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
if (displayName != null)
|
||||
project.setDisplayName(displayName);
|
||||
else
|
||||
project.setDisplayName(projectName);
|
||||
Score progress = project.getScore("§aProgress");
|
||||
progress.setScore(this.progress);
|
||||
save();
|
||||
}
|
||||
|
||||
private void save()
|
||||
{
|
||||
if (parent == null)
|
||||
JsonManager.save(toJSONObject(),
|
||||
new File(Main.plugin.getDataFolder(), "scoreboards/projects/" + projectID + ".json"));
|
||||
else
|
||||
parent.save();
|
||||
}
|
||||
|
||||
/** This method returns the UUID of the owner of this project.
|
||||
*
|
||||
* @return the UUID of the owner, null if the owner is console. */
|
||||
public UUID getOwner()
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
/** This method returns how many sub-projects can be created within this project, depending on the permissions of the project owner.</br>
|
||||
* </br>
|
||||
* Please note that as of Version 3.0.x, this value is always 5 and not respecting permissions.
|
||||
*
|
||||
* @return The maximum amount of sub-projects this project can have. */
|
||||
public int getMaxSubprojects()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
/** This method returns an unmodifiable copy of the sub-projects. If you want to modify the list, use the corresponding add/delete/clear methods</br>
|
||||
* of the project holding the list. You can still perform actions on all sub-projects as usual.
|
||||
*
|
||||
* @return An unmodifiable copy of the sub-projects list. */
|
||||
public synchronized List<Project> getSubProjects()
|
||||
{
|
||||
return Collections.unmodifiableList(subs);
|
||||
}
|
||||
|
||||
/** This method returns the scoreboard generated by the project status.
|
||||
*
|
||||
* @return the scoreboard object. */
|
||||
public Scoreboard getScoreboard()
|
||||
{
|
||||
return scoreboard;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.redstoner.modules.scoreboard;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.redstoner.misc.JsonManager;
|
||||
import com.redstoner.misc.Main;
|
||||
|
||||
public class ProjectManager
|
||||
{
|
||||
private static File dataFile = new File(Main.plugin.getDataFolder(), "projectIDs.json");
|
||||
private static JSONObject IDs;
|
||||
|
||||
static
|
||||
{
|
||||
IDs = JsonManager.getObject(dataFile);
|
||||
if (IDs == null)
|
||||
IDs = new JSONObject();
|
||||
}
|
||||
|
||||
/** This method generates a unique identifier for a project by name.
|
||||
*
|
||||
* @param name The name of the project.
|
||||
* @return The project identifier, as [name]#[ID]. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String getNextID(String name)
|
||||
{
|
||||
Object raw = IDs.get(name);
|
||||
int i = 1;
|
||||
if (raw != null)
|
||||
i = (int) raw + 1;
|
||||
IDs.put(name, i);
|
||||
save();
|
||||
return name + "#" + i;
|
||||
}
|
||||
|
||||
/** Saves the current state into a file. */
|
||||
private static void save()
|
||||
{
|
||||
JsonManager.save(IDs, dataFile);
|
||||
}
|
||||
|
||||
/** This method finds the currently active project by a CommandSender and will return it as part of the tree.
|
||||
*
|
||||
* @param sender The sender of whom the project is to be found.
|
||||
* @return the currently active project of the sender or null, if none are active. */
|
||||
public static Project getCurrentProject(CommandSender sender)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
package com.redstoner.modules.scoreboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
import com.nemez.cmdmgr.CommandManager;
|
||||
import com.redstoner.annotations.AutoRegisterListener;
|
||||
import com.redstoner.annotations.Version;
|
||||
import com.redstoner.exceptions.MissingVersionException;
|
||||
import com.redstoner.misc.JsonManager;
|
||||
import com.redstoner.misc.Main;
|
||||
import com.redstoner.misc.Utils;
|
||||
import com.redstoner.misc.VersionHelper;
|
||||
import com.redstoner.modules.Module;
|
||||
|
||||
@AutoRegisterListener
|
||||
@Version(major = 3, minor = 0, revision = 0, compatible = 3)
|
||||
public class Scoreboards implements Module, Listener
|
||||
{
|
||||
final File cmdFile = new File(
|
||||
new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile()).getParentFile(),
|
||||
"Scoreboard.cmd");
|
||||
final File scoreboardsFolder = new File(Main.plugin.getDataFolder(), "scoreboards");
|
||||
HashMap<CommandSender, JSONObject> playerData = new HashMap<CommandSender, JSONObject>();
|
||||
|
||||
@Override
|
||||
public boolean onEnable()
|
||||
{
|
||||
if (!scoreboardsFolder.exists())
|
||||
scoreboardsFolder.mkdirs();
|
||||
playerData.put(Bukkit.getConsoleSender(),
|
||||
JsonManager.getObject(new File(scoreboardsFolder, "scoreboards/players/console.json")));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postEnable()
|
||||
{
|
||||
CommandManager.registerCommand(cmdFile, this, Main.plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
save();
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
p.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
}
|
||||
playerData.remove(Bukkit.getConsoleSender());
|
||||
}
|
||||
|
||||
private void save()
|
||||
{
|
||||
JsonManager.save(playerData.get(Bukkit.getConsoleSender()),
|
||||
new File(scoreboardsFolder, "scoreboards/players/console.json"));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
JSONObject data = JsonManager.getObject(
|
||||
new File(scoreboardsFolder, "scoreboards/players/" + player.getUniqueId().toString() + ".json"));
|
||||
if (data == null)
|
||||
data = new JSONObject();
|
||||
playerData.put(player, data);
|
||||
Project currentProject = ProjectManager.getCurrentProject(player);
|
||||
if (currentProject == null)
|
||||
return;
|
||||
else
|
||||
player.setScoreboard(currentProject.getScoreboard());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
JsonManager.save(playerData.remove(player),
|
||||
new File(scoreboardsFolder, "scoreboards/players/" + player.getUniqueId().toString() + ".json"));
|
||||
}
|
||||
|
||||
@Command(hook = "project")
|
||||
public boolean project(CommandSender sender) throws MissingVersionException
|
||||
{
|
||||
Utils.sendMessage(sender, null, "This server is running version" + VersionHelper.getVersion(this.getClass()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command(hook = "create")
|
||||
public boolean createProject(CommandSender sender, boolean sub, String name)
|
||||
{
|
||||
JSONObject data = playerData.get(sender);
|
||||
if (!sub)
|
||||
{
|
||||
int max = Integer.parseInt(getPermissionContent(sender, "utils.scoreboards.projects.amount."));
|
||||
int amount = 0;
|
||||
Object raw = data.get("amount");
|
||||
if (raw != null)
|
||||
amount = (int) raw;
|
||||
if (amount >= max)
|
||||
{
|
||||
Utils.sendErrorMessage(sender, null, "You have already reached the maximum amount of " + max
|
||||
+ " projects! Delete an old project before you create a new one!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Project currentProject = ProjectManager.getCurrentProject(sender);
|
||||
int max = currentProject.getMaxSubprojects();
|
||||
int amount = currentProject.getSubProjects().size();
|
||||
Object raw = data.get("amount");
|
||||
if (raw != null)
|
||||
amount = (int) raw;
|
||||
if (amount >= max)
|
||||
{
|
||||
Utils.sendErrorMessage(sender, null, "You have already reached the maximum amount of " + max
|
||||
+ " projects! Delete an old project before you create a new one!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String getPermissionContent(CommandSender sender, String permnode)
|
||||
{
|
||||
Set<PermissionAttachmentInfo> perms = sender.getEffectivePermissions();
|
||||
for (PermissionAttachmentInfo perm : perms)
|
||||
if (perm.getPermission().toString().startsWith(permnode))
|
||||
return perm.getPermission().replace(permnode, "");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
command project {
|
||||
[empty] {
|
||||
help Prints version info.;
|
||||
run project;
|
||||
perm utils.scoreboards;
|
||||
}
|
||||
create [flag:-s] [string:name] {
|
||||
help Creates a new Project. The -s flag indicates that you are trying to create a new sub-project instead.;
|
||||
run create -s name;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
delete {
|
||||
help Deletes the current project. This will also delete the entire branch attached to it, but no parents.;
|
||||
run delete;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
explore [string:name] {
|
||||
help Switches to the specified project. If you have multiple projects with the same name reachable in one step (example: you are in 5x5_top and want to go to 5x5_top_trigger, but you also have a project called trigger) then you need to specify the full path like this: 5x5_top_trigger;
|
||||
run explore name;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
hide {
|
||||
help Deselects the current project. Use the &e/project explore &7command to view it again!;
|
||||
run hide;
|
||||
}
|
||||
option {
|
||||
help Opens an interactive option menu to let you change the projects settings.;
|
||||
run optionMenu;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
option [string:option] {
|
||||
help Opens an interactive option menu to let you change the specified setting.;
|
||||
run optionName name;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
option [string:option] [string:value...] {
|
||||
help Lets you directly modify the options of a project. If no value is specified, an interactive menu opens.;
|
||||
run option name value;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
manage {
|
||||
help Opns an interactive menu that lets you manage the project in its entirety.;
|
||||
run manage;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
invite [flag:-e] [string:name] {
|
||||
help Invites a player to the current project and all sub projects. If the -e is set, subprojects will be excluded.;
|
||||
run invite e name;
|
||||
perm utils.scoreboards.use;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user