Skip to content

Commit

Permalink
huge pile of cleanups
Browse files Browse the repository at this point in the history
semi-automated
  • Loading branch information
mcmonkey4eva committed Jan 6, 2020
1 parent 51f639d commit 732afde
Show file tree
Hide file tree
Showing 52 changed files with 99 additions and 245 deletions.
Expand Up @@ -29,7 +29,6 @@ public class HorseJumpsScriptEvent extends BukkitScriptEvent implements Listener
// @Context
// <context.entity> returns the EntityTag of the horse.
// <context.color> returns an ElementTag of the horse's color.
// <context.variant> returns an ElementTag of the horse's variant.
// <context.power> returns an ElementTag(Decimal) of the jump's power.
//
// @Determine
Expand All @@ -44,7 +43,6 @@ public HorseJumpsScriptEvent() {
public static HorseJumpsScriptEvent instance;
public EntityTag entity;
public ElementTag color;
public ElementTag variant;
public Float power;
public HorseJumpEvent event;

Expand All @@ -61,7 +59,7 @@ public boolean matches(ScriptPath path) {
String arg2 = path.eventArgLowerAt(1);
String tamed = arg2.equals("jumps") ? arg1 : arg2;

if (!tryEntity(entity, tamed) || !tamed.equals(CoreUtilities.toLowerCase(variant.toString()))) {
if (!tryEntity(entity, tamed)) {
return false;
}

Expand Down Expand Up @@ -98,9 +96,6 @@ public ObjectTag getContext(String name) {
else if (name.equals("color")) {
return color;
}
else if (name.equals("variant")) {
return variant;
}
else if (name.equals("power")) {
return new ElementTag(power);
}
Expand All @@ -112,7 +107,6 @@ public void onHorseJumps(HorseJumpEvent event) {
if (event.getEntity() instanceof Horse) {
entity = new EntityTag(event.getEntity());
color = new ElementTag(((Horse) event.getEntity()).getColor().name());
variant = new ElementTag(event.getEntity().getVariant().name());
power = event.getPower();
this.event = event;
fire(event);
Expand Down
Expand Up @@ -70,12 +70,12 @@ public boolean matches(ScriptPath path) {
if (!runInCheck(path, location)) {
return false;
}
if (!runWithCheck(path, new ItemTag(event.getPlayer().getItemInHand()))) {
if (!runWithCheck(path, new ItemTag(event.getPlayer().getEquipment().getItemInMainHand()))) {
return false;
}
// Deprecated in favor of with: format
if (path.eventArgLowerAt(3).equals("with")
&& !tryItem(new ItemTag(event.getPlayer().getItemInHand()), path.eventArgLowerAt(4))) {
&& !tryItem(new ItemTag(event.getPlayer().getEquipment().getItemInMainHand()), path.eventArgLowerAt(4))) {
return false;
}
return super.matches(path);
Expand Down
Expand Up @@ -137,7 +137,7 @@ public void onPlayerDragsInInv(InventoryDragEvent event) {
@Override
public void run() {
entity.getPlayerEntity().updateInventory();
if (holder != null && holder instanceof Player) {
if (holder instanceof Player) {
((Player) holder).updateInventory();
}
}
Expand Down
Expand Up @@ -114,7 +114,7 @@ public void playerRightClicksEntityHandler(PlayerInteractEntityEvent event) {
return;
}
entity = new EntityTag(event.getRightClicked());
item = new ItemTag(event.getPlayer().getItemInHand());
item = new ItemTag(event.getPlayer().getEquipment().getItemInMainHand());
this.event = event;
fire(event);
}
Expand Down
Expand Up @@ -74,9 +74,7 @@ private static class PlayerProfileEditorListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
if (fakeProfiles.containsKey(uuid)) {
fakeProfiles.remove(uuid);
}
fakeProfiles.remove(uuid);
}
}
}
Expand Up @@ -3,6 +3,7 @@
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.util.BoundingBox;
import com.denizenscript.denizen.nms.util.jnbt.CompoundTag;
import com.denizenscript.denizen.utilities.DenizenAPI;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand Down Expand Up @@ -103,8 +104,8 @@ public class EnforcePlayerHides implements Listener {
public void onPlayerJoin(PlayerJoinEvent event) {
for (UUID id : hiddenByDefaultPlayers) {
Entity pTarget = Bukkit.getEntity(id);
if (pTarget != null && pTarget instanceof Player) {
event.getPlayer().hidePlayer((Player) pTarget);
if (pTarget instanceof Player) {
event.getPlayer().hidePlayer(DenizenAPI.getCurrentInstance(), (Player) pTarget);
}
}
final Player pl = event.getPlayer();
Expand Down
Expand Up @@ -27,11 +27,6 @@ public ActionHandler(Denizen denizen) {
this.denizen = denizen;
}

public String doAction(String actionName, NPCTag npc, PlayerTag player, AssignmentScriptContainer assignment) {
return doAction(actionName, npc, player, assignment, null);
}


public String doAction(String actionName, NPCTag npc, PlayerTag player, AssignmentScriptContainer assignment, Map<String, ObjectTag> context) {

if (context == null) {
Expand Down
Expand Up @@ -13,7 +13,6 @@
import net.citizensnpcs.npc.ai.speech.TalkableEntity;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -136,9 +135,7 @@ private void talkToBystanders(Talkable talkable, String text, DenizenSpeechConte
double range = context.getChatRange();
List<Entity> bystanderEntities = new ArrayList<>();
if (range == 0D) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
bystanderEntities.add(player);
}
bystanderEntities.addAll(Bukkit.getServer().getOnlinePlayers());
}
else {
bystanderEntities = talkable.getEntity().getNearbyEntities(range, range, range);
Expand Down
Expand Up @@ -274,7 +274,7 @@ public void onDeath(EntityDeathEvent deathEvent) {
}
else if (killerEntity instanceof Projectile) {
ProjectileSource shooter = ((Projectile) killerEntity).getShooter();
if (shooter != null && shooter instanceof LivingEntity) {
if (shooter instanceof LivingEntity) {

context.put("shooter", new EntityTag((LivingEntity) shooter).getDenizenObject());
if (shooter instanceof Player) {
Expand Down
Expand Up @@ -108,9 +108,7 @@ public void setConstant(String name, String value) {
* @param name name of the constant, case in-sensitive
*/
public void removeConstant(String name) {
if (constants.containsKey(CoreUtilities.toLowerCase(name))) {
constants.remove(CoreUtilities.toLowerCase(name));
}
constants.remove(CoreUtilities.toLowerCase(name));
}


Expand Down
Expand Up @@ -49,14 +49,11 @@ public void run() {
int range = frange.getLast().asInteger();
boolean acceptnpc = facceptnpc.getLast().asBoolean();
List<Entity> nearby = liveEnt.getNearbyEntities(range, range, range);
List<Entity> removeme = new ArrayList<>();
removeme.addAll(inrange);
List<Entity> removeme = new ArrayList<>(inrange);
for (Entity ent : nearby) {
if (ent instanceof LivingEntity && (!(ent instanceof Player) || EntityTag.isCitizensNPC(ent))
&& (acceptnpc || (!EntityTag.isCitizensNPC(ent)))) {
if (removeme.contains(ent)) {
removeme.remove(ent);
}
removeme.remove(ent);
if (!inrange.contains(ent)) {
inrange.add(ent);
callAction("enter", ent);
Expand Down
Expand Up @@ -268,9 +268,8 @@ public static void registerTags() {
}
int x = Integer.parseInt(coords.get(0));
int z = Integer.parseInt(coords.get(1));
ChunkTag chunk = object;

return new ChunkTag(chunk.world, chunk.chunkX + x, chunk.chunkZ + z);
return new ChunkTag(object.world, object.chunkX + x, object.chunkZ + z);

});

Expand All @@ -296,9 +295,8 @@ public static void registerTags() {
}
int x = Integer.parseInt(coords.get(0));
int z = Integer.parseInt(coords.get(1));
ChunkTag chunk = object;

return new ChunkTag(chunk.world, chunk.chunkX - x, chunk.chunkZ - z);
return new ChunkTag(object.world, object.chunkX - x, object.chunkZ - z);

});

Expand Down Expand Up @@ -349,9 +347,8 @@ public static void registerTags() {
// Returns a cuboid of this chunk.
// -->
registerTag("cuboid", (attribute, object) -> {
ChunkTag chunk = object;
return new CuboidTag(new Location(chunk.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16),
new Location(chunk.getWorld(), chunk.getX() * 16 + 15, 255, chunk.getZ() * 16 + 15));
return new CuboidTag(new Location(object.getWorld(), object.getX() * 16, 0, object.getZ() * 16),
new Location(object.getWorld(), object.getX() * 16 + 15, 255, object.getZ() * 16 + 15));
});

// <--[tag]
Expand Down
Expand Up @@ -133,7 +133,7 @@ public static NPCTag getNPCFrom(Entity entity) {
}

public static boolean isPlayer(Entity entity) {
return entity != null && entity instanceof Player && !isNPC(entity);
return entity instanceof Player && !isNPC(entity);
}

public static PlayerTag getPlayerFrom(Entity entity) {
Expand Down
Expand Up @@ -2118,9 +2118,6 @@ else if (item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName
// -->
registerTag("location", (attribute, object) -> {
LocationTag location = object.getLocation();
if (location == null) {
return null;
}
return location;
});

Expand Down Expand Up @@ -2250,9 +2247,6 @@ else if (slot > object.getInventory().getSize() - 1) {
// -->
registerTag("equipment", (attribute, object) -> {
ListTag equipment = object.getEquipment();
if (equipment == null) {
return null;
}
return equipment;
});

Expand Down Expand Up @@ -2353,9 +2347,6 @@ else if ((object.inventory instanceof FurnaceInventory)) {
// -->
registerTag("fuel", (attribute, object) -> {
ItemTag fuel = object.getFuel();
if (fuel == null) {
return null;
}
return fuel;
});

Expand All @@ -2368,9 +2359,6 @@ else if ((object.inventory instanceof FurnaceInventory)) {
// -->
registerTag("input", (attribute, object) -> {
ItemTag smelting = object.getInput();
if (smelting == null) {
return null;
}
return smelting;
});
registerTag("smelting", tagProcessor.registeredObjectTags.get("input"));
Expand Down
Expand Up @@ -789,12 +789,11 @@ public static void registerTags() {
if (attribute.getAttribute(2).equals("formatted")) {
return object;
}
ItemTag item = object;
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13) &&
item.getItemStack().hasItemMeta() && item.getItemStack().getItemMeta() instanceof BlockStateMeta) {
return new MaterialTag(new ModernBlockData(((BlockStateMeta) item.getItemStack().getItemMeta()).getBlockState()));
object.getItemStack().hasItemMeta() && object.getItemStack().getItemMeta() instanceof BlockStateMeta) {
return new MaterialTag(new ModernBlockData(((BlockStateMeta) object.getItemStack().getItemMeta()).getBlockState()));
}
return item.getMaterial();
return object.getMaterial();
});

// <--[tag]
Expand Down Expand Up @@ -858,10 +857,9 @@ public static void registerTags() {
// -->
registerTag("recipe_ids", (attribute, object) -> {
String type = attribute.hasContext(1) ? CoreUtilities.toLowerCase(attribute.getContext(1)) : null;
ItemTag item = object;
ItemScriptContainer container = item.isItemscript() ? ItemScriptHelper.getItemScriptContainer(item.getItemStack()) : null;
ItemScriptContainer container = object.isItemscript() ? ItemScriptHelper.getItemScriptContainer(object.getItemStack()) : null;
ListTag list = new ListTag();
for (Recipe recipe : Bukkit.getRecipesFor(item.getItemStack())) {
for (Recipe recipe : Bukkit.getRecipesFor(object.getItemStack())) {
if (!Utilities.isRecipeOfType(recipe, type)) {
continue;
}
Expand Down
Expand Up @@ -271,13 +271,12 @@ else if (split.size() == 5)
// x,y,z,pitch,yaw
{
try {
LocationTag output = new LocationTag(null,
return new LocationTag(null,
Double.valueOf(split.get(0)),
Double.valueOf(split.get(1)),
Double.valueOf(split.get(2)),
Float.valueOf(split.get(3)),
Float.valueOf(split.get(4)));
return output;
}
catch (Exception e) {
if (context == null || context.debug) {
Expand Down Expand Up @@ -1044,8 +1043,7 @@ public static void registerTags() {
if (!object.isChunkLoadedSafe()) {
return null;
}
ObjectTag obj = ElementTag.handleNull(object.identify() + ".inventory", object.getInventory(), "InventoryTag", attribute.hasAlternative());
return obj;
return ElementTag.handleNull(object.identify() + ".inventory", object.getInventory(), "InventoryTag", attribute.hasAlternative());
});

// <--[tag]
Expand Down
Expand Up @@ -800,12 +800,11 @@ public static void registerTags() {
// Returns the explosion resistance for all blocks of this material type.
// -->
registerTag("block_resistance", (attribute, object) -> {
MaterialTag material = object;
if (!NMSHandler.getBlockHelper().hasBlock(material.getMaterial())) {
if (!NMSHandler.getBlockHelper().hasBlock(object.getMaterial())) {
Debug.echoError("Provided material does not have a placeable block.");
return null;
}
return new ElementTag(NMSHandler.getBlockHelper().getBlockResistance(material.getMaterial()));
return new ElementTag(NMSHandler.getBlockHelper().getBlockResistance(object.getMaterial()));
});

// <--[tag]
Expand All @@ -815,12 +814,11 @@ public static void registerTags() {
// Returns the value representing how hard a material, used as a basis for calculating the time it takes to break.
// -->
registerTag("hardness", (attribute, object) -> {
MaterialTag material = object;
if (!material.getMaterial().isBlock()) {
if (!object.getMaterial().isBlock()) {
Debug.echoError("Provided material does not have a placeable block.");
return null;
}
return new ElementTag(material.getMaterial().getHardness());
return new ElementTag(object.getMaterial().getHardness());
});

// <--[tag]
Expand Down Expand Up @@ -892,11 +890,10 @@ public static void registerTags() {
// Returns an item of the material.
// -->
registerTag("item", (attribute, object) -> {
MaterialTag material = object;
ItemTag item = new ItemTag(material, 1);
ItemTag item = new ItemTag(object, 1);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
if (item.getItemStack().hasItemMeta() && item.getItemStack().getItemMeta() instanceof BlockStateMeta) {
((BlockStateMeta) item.getItemStack().getItemMeta()).setBlockState(material.modernData.getBlockState());
((BlockStateMeta) item.getItemStack().getItemMeta()).setBlockState(object.modernData.getBlockState());
}
}
return item;
Expand Down
Expand Up @@ -2725,7 +2725,7 @@ public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("attack_cooldown") && mechanism.requireObject(DurationTag.class)) {
NMSHandler.getPlayerHelper().setAttackCooldown(getPlayerEntity(),
mechanism.getValue().asType(DurationTag.class).getTicksAsInt());
mechanism.getValue().asType(DurationTag.class, mechanism.context).getTicksAsInt());
}

// <--[mechanism]
Expand Down
Expand Up @@ -57,12 +57,7 @@ else if (object.queue.getEntries().size() > 0) {
else if (!attribute.hasAlternative()) {
Debug.echoError(object.queue, "Can't determine a linked NPC.");
}
if (npc == null) {
return null;
}
else {
return npc;
}
return npc;
});

// <--[tag]
Expand All @@ -83,12 +78,7 @@ else if (object.queue.getEntries().size() > 0) {
else {
Debug.echoError(object.queue, "Can't determine a linked player.");
}
if (player == null) {
return null;
}
else {
return player;
}
return player;
});
}

Expand Down

0 comments on commit 732afde

Please sign in to comment.