Skip to content

Commit

Permalink
fix all list handlings in ServerTagBase
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 22, 2019
1 parent 36798fb commit 9fbb648
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
Expand Up @@ -8,7 +8,6 @@
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.scripts.triggers.AbstractTrigger;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -294,13 +293,13 @@ private boolean isCloseEnough(Player player, NPCTag npc) {
@EventHandler // TODO: Does this have any point?
public void checkMaxProximities(ScriptReloadEvent event) {

for (String script : ScriptRegistry._getScriptNames()) {
//for (String script : ScriptRegistry._getScriptNames()) {
//
// TODO: Check interact scripts for proximity triggers and ranges.
// Find largest number, add 10, and set it as maxProximityRange.
// For now, let's assume 25.
//
}
//}
}

private static Map<UUID, Set<Integer>> proximityTracker = new ConcurrentHashMap<>(8, 0.9f, 1);
Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.notable.Notable;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import com.denizenscript.denizencore.scripts.containers.core.WorldScriptContainer;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.ReplaceableTagEvent;
Expand Down Expand Up @@ -615,15 +616,15 @@ public void serverTag(ReplaceableTagEvent event) {
for (Map.Entry<String, Class> typeClass : NotableManager.getReverseClassIdMap().entrySet()) {
if (type.equals(CoreUtilities.toLowerCase(typeClass.getKey()))) {
for (Object notable : NotableManager.getAllType(typeClass.getValue())) {
allNotables.add(((ObjectTag) notable).identify());
allNotables.addObject((ObjectTag) notable);
}
break;
}
}
}
else {
for (Notable notable : NotableManager.notableObjects.values()) {
allNotables.add(((ObjectTag) notable).identify());
allNotables.addObject((ObjectTag) notable);
}
}
event.setReplaced(allNotables.getAttribute(attribute.fulfill(1)));
Expand Down Expand Up @@ -787,13 +788,13 @@ public void serverTag(ReplaceableTagEvent event) {
ListTag list = new ListTag();
if (EventsOne != null) {
for (WorldScriptContainer script : EventsOne) {
list.add("s@" + script.getName());
list.addObject(new ScriptTag(script));
}
}
if (EventsTwo != null) {
for (WorldScriptContainer script : EventsTwo) {
if (!list.contains("s@" + script.getName())) {
list.add("s@" + script.getName());
if (!list.contains(new ScriptTag(script).identify())) {
list.addObject(new ScriptTag(script));
}
}
}
Expand Down Expand Up @@ -829,7 +830,7 @@ public void serverTag(ReplaceableTagEvent event) {
ListTag npcs = new ListTag();
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.getName().equalsIgnoreCase(attribute.getContext(1))) {
npcs.add(NPCTag.mirrorCitizensNPC(npc).identify());
npcs.addObject(NPCTag.mirrorCitizensNPC(npc));
}
}
event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
Expand Down Expand Up @@ -1106,13 +1107,8 @@ public void serverTag(ReplaceableTagEvent event) {
return;
}

// <--[tag]
// @attribute <server.list_plugin_names>
// @returns ListTag
// @description
// Gets a list of currently enabled plugin names from the server.
// -->
if (attribute.startsWith("list_plugin_names")) {
Deprecations.serverPluginNamesTag.warn(attribute.context);
ListTag plugins = new ListTag();
for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()) {
plugins.add(plugin.getName());
Expand All @@ -1129,8 +1125,8 @@ public void serverTag(ReplaceableTagEvent event) {
// -->
if (attribute.startsWith("list_scripts")) {
ListTag scripts = new ListTag();
for (String str : ScriptRegistry._getScriptNames()) {
scripts.add("s@" + str);
for (ScriptContainer script : ScriptRegistry.scriptContainers.values()) {
scripts.addObject(new ScriptTag(script));
}
event.setReplaced(scripts.getAttribute(attribute.fulfill(1)));
return;
Expand Down Expand Up @@ -1209,7 +1205,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.hasTrait(AssignmentTrait.class) && npc.getTrait(AssignmentTrait.class).hasAssignment()
&& npc.getTrait(AssignmentTrait.class).getAssignment().getName().equalsIgnoreCase(script.getName())) {
npcs.add(NPCTag.mirrorCitizensNPC(npc).identify());
npcs.addObject(NPCTag.mirrorCitizensNPC(npc));
}
}
event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
Expand All @@ -1229,7 +1225,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
ListTag players = new ListTag();
for (Player player : Bukkit.getOnlinePlayers()) {
if (DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(new PlayerTag(player), flag).size() > 0) {
players.add(new PlayerTag(player).identify());
players.addObject(new PlayerTag(player));
}
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
Expand All @@ -1248,7 +1244,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
ListTag players = new ListTag();
for (Map.Entry<String, UUID> entry : PlayerTag.getAllPlayers().entrySet()) {
if (DenizenAPI.getCurrentInstance().flagManager().getPlayerFlag(new PlayerTag(entry.getValue()), flag).size() > 0) {
players.add(new PlayerTag(entry.getValue()).identify());
players.addObject(new PlayerTag(entry.getValue()));
}
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
Expand All @@ -1268,7 +1264,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
for (NPC npc : CitizensAPI.getNPCRegistry()) {
NPCTag dNpc = NPCTag.mirrorCitizensNPC(npc);
if (dNpc.isSpawned() && FlagManager.npcHasFlag(dNpc, flag)) {
npcs.add(dNpc.identify());
npcs.addObject(dNpc);
}
}
event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
Expand All @@ -1288,7 +1284,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
for (NPC npc : CitizensAPI.getNPCRegistry()) {
NPCTag dNpc = NPCTag.mirrorCitizensNPC(npc);
if (FlagManager.npcHasFlag(dNpc, flag)) {
npcs.add(dNpc.identify());
npcs.addObject(dNpc);
}
}
event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
Expand All @@ -1304,7 +1300,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
if (attribute.startsWith("list_npcs") && Depends.citizens != null) {
ListTag npcs = new ListTag();
for (NPC npc : CitizensAPI.getNPCRegistry()) {
npcs.add(NPCTag.mirrorCitizensNPC(npc).identify());
npcs.addObject(NPCTag.mirrorCitizensNPC(npc));
}
event.setReplaced(npcs.getAttribute(attribute.fulfill(1)));
return;
Expand All @@ -1319,7 +1315,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
if (attribute.startsWith("list_worlds")) {
ListTag worlds = new ListTag();
for (World world : Bukkit.getWorlds()) {
worlds.add(WorldTag.mirrorBukkitWorld(world).identify());
worlds.addObject(WorldTag.mirrorBukkitWorld(world));
}
event.setReplaced(worlds.getAttribute(attribute.fulfill(1)));
return;
Expand All @@ -1334,7 +1330,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
if (attribute.startsWith("list_plugins")) {
ListTag plugins = new ListTag();
for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()) {
plugins.add(new PluginTag(plugin).identify());
plugins.addObject(new PluginTag(plugin));
}
event.setReplaced(plugins.getAttribute(attribute.fulfill(1)));
return;
Expand All @@ -1349,7 +1345,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
if (attribute.startsWith("list_players")) {
ListTag players = new ListTag();
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
players.add(PlayerTag.mirrorBukkitPlayer(player).identify());
players.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
return;
Expand All @@ -1364,7 +1360,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
if (attribute.startsWith("list_online_players")) {
ListTag players = new ListTag();
for (Player player : Bukkit.getOnlinePlayers()) {
players.add(PlayerTag.mirrorBukkitPlayer(player).identify());
players.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
return;
Expand All @@ -1380,7 +1376,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
ListTag players = new ListTag();
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (!player.isOnline()) {
players.add(PlayerTag.mirrorBukkitPlayer(player).identify());
players.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
Expand All @@ -1396,7 +1392,7 @@ else if (CoreUtilities.toLowerCase(entry.getKey()).contains(matchInput) && match
if (attribute.startsWith("list_banned_players")) {
ListTag banned = new ListTag();
for (OfflinePlayer player : Bukkit.getBannedPlayers()) {
banned.add(PlayerTag.mirrorBukkitPlayer(player).identify());
banned.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
event.setReplaced(banned.getAttribute(attribute.fulfill(1)));
return;
Expand Down Expand Up @@ -1502,7 +1498,7 @@ else if (attribute.startsWith("source")) {
if (attribute.startsWith("list_ops")) {
ListTag players = new ListTag();
for (OfflinePlayer player : Bukkit.getOperators()) {
players.add(PlayerTag.mirrorBukkitPlayer(player).identify());
players.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
return;
Expand All @@ -1518,7 +1514,7 @@ else if (attribute.startsWith("source")) {
ListTag players = new ListTag();
for (OfflinePlayer player : Bukkit.getOperators()) {
if (player.isOnline()) {
players.add(PlayerTag.mirrorBukkitPlayer(player).identify());
players.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
Expand All @@ -1535,7 +1531,7 @@ else if (attribute.startsWith("source")) {
ListTag players = new ListTag();
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (player.isOp() && !player.isOnline()) {
players.add(PlayerTag.mirrorBukkitPlayer(player).identify());
players.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
}
event.setReplaced(players.getAttribute(attribute.fulfill(1)));
Expand Down
Expand Up @@ -388,7 +388,7 @@ public void scripts(CommandContext args, CommandSender sender) throws CommandExc
filter = args.getFlag("filter");
}
// Get script names from the scripts.yml in memory
Set<String> scripts = ScriptRegistry._getScriptNames();
Set<String> scripts = ScriptRegistry.scriptContainers.keySet();
// New Paginator to display script names
Paginator paginator = new Paginator().header("Scripts");
paginator.addLine("<e>Key: <a>Type <b>Name");
Expand Down

0 comments on commit 9fbb648

Please sign in to comment.