Skip to content

Commit

Permalink
formalize more deprecations
Browse files Browse the repository at this point in the history
also undeprecate a thing that has a better way now
  • Loading branch information
mcmonkey4eva committed Sep 18, 2019
1 parent 7258925 commit 78e7dc8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 53 deletions.
@@ -1,8 +1,11 @@
package com.denizenscript.denizen.events.block;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.utilities.blocks.ModernBlockData;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
Expand Down Expand Up @@ -30,7 +33,7 @@ public class BlockBuiltScriptEvent extends BukkitScriptEvent implements Listener
// @Context
// <context.location> returns the LocationTag of the block the player is trying to build on.
// <context.old_material> returns the MaterialTag of the block the player is trying to build on.
// <context.new_material> Deprecated, returns the MaterialTag of the block the player is trying to build.
// <context.new_material> returns the MaterialTag of the block the player is trying to build.
//
// @Determine
// "BUILDABLE" to allow the building.
Expand Down Expand Up @@ -106,7 +109,12 @@ else if (name.equals("old_material")) {
public void onBlockBuilt(BlockCanBuildEvent event) {
location = new LocationTag(event.getBlock().getLocation());
old_material = new MaterialTag(event.getBlock());
new_material = new MaterialTag(event.getMaterial()); // Deprecated because it doesn't have proper data
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
new_material = new MaterialTag(new ModernBlockData(event.getBlockData()));
}
else {
new_material = new MaterialTag(event.getMaterial());
}
cancelled = !event.isBuildable();
this.event = event;
fire(event);
Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.utilities.Deprecations;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDispenseEvent;
Expand Down Expand Up @@ -36,7 +37,6 @@ public class BlockDispensesScriptEvent extends BukkitScriptEvent implements List
// <context.velocity> returns a LocationTag vector of the velocity the item will be shot at.
//
// @Determine
// Element(Decimal) (DEPRECATED) to multiply the velocity by the given amount.
// LocationTag to set the velocity the item will be shot at.
// ItemTag to set the item being shot.
//
Expand Down Expand Up @@ -77,6 +77,7 @@ public String getName() {
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
if (ArgumentHelper.matchesDouble(determination)) {
Deprecations.blockDispensesItemDetermination.warn();
event.setVelocity(event.getVelocity().multiply(ArgumentHelper.getDoubleFrom(determination)));
return true;
}
Expand Down
Expand Up @@ -7,6 +7,7 @@
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.Deprecations;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
Expand All @@ -33,7 +34,6 @@ public class PlayerRightClicksEntityScriptEvent extends BukkitScriptEvent implem
// @Context
// <context.entity> returns the EntityTag the player is clicking on.
// <context.item> returns the ItemTag the player is clicking with.
// <context.location> returns a LocationTag of the clicked entity. NOTE: DEPRECATED IN FAVOR OF <context.entity.location>
// <context.click_position> returns a LocationTag of the click position (as a world-less vector, relative to the entity's center). This is only available when clicking armor stands.
//
// -->
Expand All @@ -42,7 +42,6 @@ public class PlayerRightClicksEntityScriptEvent extends BukkitScriptEvent implem
PlayerInteractEntityEvent event;
EntityTag entity;
ItemTag item;
LocationTag location;

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
Expand Down Expand Up @@ -89,7 +88,8 @@ else if (name.equals("item")) {
return item;
}
else if (name.equals("location")) {
return location;
Deprecations.playerRightClicksEntityContext.warn();
return entity.getLocation();
}
else if (name.equals("click_position") && event instanceof PlayerInteractAtEntityEvent) {
return new LocationTag(((PlayerInteractAtEntityEvent) event).getClickedPosition());
Expand All @@ -116,7 +116,6 @@ public void playerRightClicksEntityHandler(PlayerInteractEntityEvent event) {
}
entity = new EntityTag(event.getRightClicked());
item = new ItemTag(event.getPlayer().getItemInHand());
location = new LocationTag(event.getRightClicked().getLocation());
this.event = event;
fire(event);
}
Expand Down
Expand Up @@ -128,17 +128,6 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
.getObjectAttribute(attribute.fulfill(1));
}

// Deprecated in favor of pages.escape_contents
if (attribute.startsWith("pages.escaped")) {
StringBuilder output = new StringBuilder();
for (String page : bookInfo.getPages()) {
output.append(EscapeTagBase.escape(page)).append("|");
}
return new ListTag(output.length() > 0 ?
output.substring(0, output.length() - 1) : output.toString())
.getObjectAttribute(attribute.fulfill(2));
}

// <--[tag]
// @attribute <ItemTag.book.pages>
// @returns ListTag
Expand Down
Expand Up @@ -54,29 +54,14 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
return null;
}

// <--[tag]
// @attribute <ItemTag.spawn_id>
// @returns ElementTag(Number)
// @group properties
// @mechanism ItemTag.spawn_id
// @description
// NOTE: ID numbers are deprecated since 1.11
// Use <ItemTag.spawn_type> instead!
// Returns the spawn egg number of the item.
// -->
if ((attribute.startsWith("spawn_id") || attribute.startsWith("spawn_egg_entity"))
&& getEntityType() != null) {
return new ElementTag(getEntityType().getTypeId())
.getObjectAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <ItemTag.spawn_type>
// @returns ElementTag
// @group properties
// @mechanism ItemTag.spawn_type
// @description
// Returns the spawn egg's entity type.
// NOTE: In 1.13+, spawn eggs are distinct materials.
// -->
if (attribute.startsWith("spawn_type") && getEntityType() != null) {
return new ElementTag(getEntityType().name())
Expand All @@ -103,30 +88,13 @@ public String getPropertyId() {
@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object ItemTag
// @name spawn_id
// @input Element(Number)
// @description
// NOTE: ID numbers are deprecated since 1.11
// Use <@link mechanism ItemTag.spawn_type> instead!
// Sets what mob a spawn egg holds.
// @tags
// <ItemTag.spawn_id>
// -->
if ((mechanism.matches("spawn_id") || mechanism.matches("spawn_egg"))
&& mechanism.requireInteger()) {
SpawnEggMeta sem = (SpawnEggMeta) item.getItemStack().getItemMeta();
sem.setSpawnedType(EntityType.fromId(mechanism.getValue().asInt()));
item.getItemStack().setItemMeta(sem);
}

// <--[mechanism]
// @object ItemTag
// @name spawn_type
// @input Element
// @description
// Sets what entity type a spawn egg holds.
// NOTE: In 1.13+, spawn eggs are distinct materials.
// @tags
// <ItemTag.spawn_type>
// -->
Expand Down
Expand Up @@ -1700,8 +1700,8 @@ public static void adjustServer(Mechanism mechanism) {
}
}

// Deprecated in favor of SYSTEM.redirect_logging (Core)
if (mechanism.matches("redirect_logging") && mechanism.hasValue()) {
Deprecations.serverRedirectLogging.warn();
if (!Settings.allowConsoleRedirection()) {
Debug.echoError("Console redirection disabled by administrator.");
return;
Expand Down

0 comments on commit 78e7dc8

Please sign in to comment.