Skip to content

Commit

Permalink
Merge pull request #1866 from mcmonkey4eva/master
Browse files Browse the repository at this point in the history
PR for spigot broke it
  • Loading branch information
mcmonkey4eva committed Dec 17, 2018
2 parents 946e120 + 86517c3 commit 85e4b77
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ public interface Particle {
boolean isVisible();

String getName();

default Class neededData() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.entity.Vehicle;

import java.util.List;
import java.util.regex.Pattern;

public abstract class BukkitScriptEvent extends ScriptEvent {

Expand Down Expand Up @@ -100,6 +101,23 @@ public boolean runWithCheck(ScriptContainer scriptContainer, String s, String lo
return true;
}

private static final String ASTERISK_QUOTED = Pattern.quote("*");

public String regexHandle(String input) {
if (input.startsWith("regex:")) {
return input.substring("regex:".length());
}
if (input.contains("*")) {
return Pattern.quote(input).replace(ASTERISK_QUOTED, "(.*)");
}
return null;
}

public boolean equalityCheck(String input, String compared, String regexed) {
input = CoreUtilities.toLowerCase(input);
return input.equals(compared) || (regexed != null && input.matches(regexed));
}

public boolean tryItem(dItem item, String comparedto) {
if (comparedto == null || comparedto.isEmpty() || item == null) {
return false;
Expand All @@ -121,22 +139,26 @@ public boolean tryItem(dItem item, String comparedto) {
return true;
}
}
String regexd = regexHandle(comparedto);
item = new dItem(item.getItemStack().clone());
item.setAmount(1);
if (CoreUtilities.toLowerCase(item.identifyNoIdentifier()).equals(comparedto)) {
if (equalityCheck(item.identifyNoIdentifier(), comparedto, regexd)) {
return true;
}
else if (CoreUtilities.toLowerCase(item.identifyMaterialNoIdentifier()).equals(comparedto)) {
else if (equalityCheck(item.identifyMaterialNoIdentifier(), comparedto, regexd)) {
return true;
}
else if (CoreUtilities.toLowerCase(item.identifySimpleNoIdentifier()).equals(comparedto)) {
else if (equalityCheck(item.identifySimpleNoIdentifier(), comparedto, regexd)) {
return true;
}
else if (CoreUtilities.toLowerCase(item.identifyNoIdentifier()).equals(comparedto)) {
else if (equalityCheck(item.identifyNoIdentifier(), comparedto, regexd)) {
return true;
}
item.setDurability((short) 0);
return CoreUtilities.toLowerCase(item.identifyMaterialNoIdentifier()).equals(comparedto);
if (equalityCheck(item.identifyMaterialNoIdentifier(), comparedto, regexd)) {
return true;
}
return false;
}

public boolean tryMaterial(dMaterial mat, String comparedto) {
Expand All @@ -156,16 +178,17 @@ public boolean tryMaterial(dMaterial mat, String comparedto) {
return true;
}
}
if (CoreUtilities.toLowerCase(mat.realName()).equals(comparedto)) {
String regexd = regexHandle(comparedto);
if (equalityCheck(mat.realName(), comparedto, regexd)) {
return true;
}
else if (CoreUtilities.toLowerCase(mat.identifyNoIdentifier()).equals(comparedto)) {
else if (equalityCheck(mat.identifyNoIdentifier(), comparedto, regexd)) {
return true;
}
else if (CoreUtilities.toLowerCase(mat.identifySimpleNoIdentifier()).equals(comparedto)) {
else if (equalityCheck(mat.identifySimpleNoIdentifier(), comparedto, regexd)) {
return true;
}
else if (CoreUtilities.toLowerCase(mat.identifyFullNoIdentifier()).equals(comparedto)) {
else if (equalityCheck(mat.identifyFullNoIdentifier(), comparedto, regexd)) {
return true;
}
return false;
Expand Down Expand Up @@ -195,10 +218,11 @@ else if (comparedto.equals("projectile")) {
else if (comparedto.equals("hanging")) {
return bEntity instanceof Hanging;
}
else if (entity.getEntityScript() != null && comparedto.equals(CoreUtilities.toLowerCase(entity.getEntityScript()))) {
String regexd = regexHandle(comparedto);
if (entity.getEntityScript() != null && equalityCheck(entity.getEntityScript(), comparedto, regexd)) {
return true;
}
else if (comparedto.equals(entity.getEntityType().getLowercaseName())) {
else if (equalityCheck(entity.getEntityType().getLowercaseName(), comparedto, regexd)) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void onEntityExplodes(EntityExplodeEvent event) {
blocks = new dList();
blockSet = false;
for (Block block : event.blockList()) {
blocks.add(new dLocation(block.getLocation()).identifySimple());
blocks.add(new dLocation(block.getLocation()).identify());
}
cancelled = event.isCancelled();
this.event = event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,15 @@ public static dMaterial valueOf(String string, TagContext context) {
string = string.substring(0, index);
}
Material m = Material.getMaterial(string);
if (m == null && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
m = Material.getMaterial(string, true);
if (m != null) {
m = Bukkit.getUnsafe().fromLegacy(m);
if (context == null || context.debug) {
dB.log("'" + string + "' is a legacy (pre-1.13) material name. It is now '" + m.name() + "'.");
}
}
}
if (m != null) {
if ((context == null || context.debug) && index >= 0) {
dB.log("Material ID and data magic number support is deprecated and WILL be removed in a future release. Use relevant properties instead.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name PlayEffect
// @Syntax playeffect [effect:<name>] [at:<location>|...] (data:<#.#>) (visibility:<#.#>) (quantity:<#>) (offset:<#.#>,<#.#>,<#.#>) (targets:<player>|...)
// @Syntax playeffect [effect:<name>] [at:<location>|...] (data:<#.#>) (special_data:<data>) (visibility:<#.#>) (quantity:<#>) (offset:<#.#>,<#.#>,<#.#>) (targets:<player>|...)
// @Required 2
// @Stable stable
// @Short Plays a visible or audible effect at the location.
Expand All @@ -2778,6 +2778,9 @@ public void registerCoreMembers() {
// The distinction is in whether you include the (now expected to use) "at:" prefix on your location argument.
// If you do not have this prefix, the system will assume your command is older, and will apply the 1-block height offset.
//
// Some particles will require input to the "special_data" argument. The data input is unique per particle.
// - For REDSTONE particles, the input is of format: <size>|<color>, for example: "1.2|red". Color input is any valid dColor object.
//
// @Tags
// None
//
Expand Down Expand Up @@ -3272,7 +3275,7 @@ public void registerCoreMembers() {
// Player and npc are not carried over to the new queue if not specified.
//
// @Tags
// <entry[saveName].created_queue>
// <entry[saveName].created_queue> returns the queue that was started by the run command.
//
// @Usage
// Use to run a new queue instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.*;
Expand Down Expand Up @@ -230,7 +231,7 @@ else if (scriptEntry.hasObject("path") && scriptEntry.getObject("path") != null)

// Set any delay
if (scriptEntry.hasObject("delay")) {
queue.delayUntil(System.currentTimeMillis() + ((Duration) scriptEntry.getObject("delay")).getMillis());
queue.delayUntil(DenizenCore.serverTimeMillis + ((Duration) scriptEntry.getObject("delay")).getMillis());
}

// Set any definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import net.aufdemrand.denizen.nms.abstracts.ParticleHelper;
import net.aufdemrand.denizen.nms.interfaces.Effect;
import net.aufdemrand.denizen.nms.interfaces.Particle;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dMaterial;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
Expand Down Expand Up @@ -141,6 +138,10 @@ else if (!scriptEntry.hasObject("data")

scriptEntry.addObject("data", arg.asElement());
}
else if (!scriptEntry.hasObject("special_data")
&& arg.matchesOnePrefix("special_data")) {
scriptEntry.addObject("special_data", arg.asElement());
}
else if (!scriptEntry.hasObject("qty")
&& arg.matchesPrimitive(aH.PrimitiveType.Integer)
&& arg.matchesPrefix("qty", "q", "quantity")) {
Expand Down Expand Up @@ -212,6 +213,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element no_offset = scriptEntry.getElement("no_offset");
boolean should_offset = no_offset == null || !no_offset.asBoolean();
dLocation offset = scriptEntry.getdObject("offset");
Element special_data = scriptEntry.getElement("special_data");

// Report to dB
if (scriptEntry.dbCallShouldDebug()) {
Expand All @@ -226,6 +228,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
data.debug() +
qty.debug() +
offset.debug() +
(special_data != null ? special_data.debug() : "") +
(should_offset ? aH.debugObj("note", "Location will be offset 1 block-height upward (see documentation)") : ""));
}

Expand Down Expand Up @@ -273,7 +276,31 @@ else if (particleEffect != null) {
}
}
for (Player player : players) {
particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
Class clazz = particleEffect.neededData();
if (clazz == null) {
particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
}
else {
Object dataObject = null;
if (special_data == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing required special data for particle: " + particleEffect.getName());
}
else if (clazz == org.bukkit.Particle.DustOptions.class) {
dList dataList = dList.valueOf(special_data.asString());
if (dataList.size() != 2) {
dB.echoError(scriptEntry.getResidingQueue(), "DustOptions special_data must have 2 list entries for particle: " + particleEffect.getName());
}
else {
float size = aH.getFloatFrom(dataList.get(0));
dColor color = dColor.valueOf(dataList.get(1));
dataObject = new org.bukkit.Particle.DustOptions(color.getColor(), size);
}
}
else {
dB.echoError(scriptEntry.getResidingQueue(), "Unknown particle data type: " + clazz.getCanonicalName() + " for particle: " + particleEffect.getName());
}
particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), dataObject);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
// If this block already had a delayed task, cancel it.
if (taskMap.containsKey(interactLocation)) {
try {
DenizenAPI.getCurrentInstance().getServer().getScheduler().cancelTask(taskMap.get(interactLocation));
Bukkit.getScheduler().cancelTask(taskMap.get(interactLocation));
}
catch (Exception e) {
}
}
dB.log("Setting delayed task 'SWITCH' for " + interactLocation.identify());
// Store new delayed task ID, for checking against, then schedule new delayed task.
taskMap.put(interactLocation, DenizenAPI.getCurrentInstance().getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(),
taskMap.put(interactLocation, Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(),
new Runnable() {
public void run() {
switchBlock(scriptEntry, interactLocation, SwitchState.TOGGLE, player);
Expand Down Expand Up @@ -148,36 +148,23 @@ else if ((type == MaterialCompat.OAK_TRAPDOOR
// Break off this portion of the code from execute() so it can be used in both execute and the delayed runnable
public void switchBlock(ScriptEntry scriptEntry, Location interactLocation, SwitchState switchState, Player player) {
boolean currentState = switchState(interactLocation.getBlock());
String state = switchState.toString();

// Try for a linked player
if (player == null && Bukkit.getOnlinePlayers().size() > 0) {
// If there's none, link any player
if (Bukkit.getOnlinePlayers().size() > 0) {
player = (Player) Bukkit.getOnlinePlayers().toArray()[0];
}
else if (Depends.citizens != null) {
// If there are no players, link any Human NPC
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.isSpawned() && npc.getEntity() instanceof Player) {
player = (Player) npc.getEntity();
break;
}
}
// TODO: backup if no human NPC available? (Fake EntityPlayer instance?)
}
}

if ((state.equals("ON") && !currentState) ||
(state.equals("OFF") && currentState) ||
state.equals("TOGGLE")) {
if ((switchState.equals(SwitchState.ON) && !currentState) ||
(switchState.equals(SwitchState.OFF) && currentState) ||
switchState.equals(SwitchState.TOGGLE)) {

if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
if (interactLocation.getBlock().getBlockData() instanceof Openable) {
((Openable) interactLocation.getBlock().getBlockData()).setOpen(!currentState);
Openable newState = ((Openable) interactLocation.getBlock().getBlockData());
newState.setOpen(!currentState);
interactLocation.getBlock().setBlockData(newState, true);
interactLocation.getBlock().getState().update(true, true);
}
if (interactLocation.getBlock().getBlockData() instanceof Powerable) {
((Powerable) interactLocation.getBlock().getBlockData()).setPowered(!currentState);
else if (interactLocation.getBlock().getBlockData() instanceof Powerable) {
Powerable newState = ((Powerable) interactLocation.getBlock().getBlockData());
newState.setPowered(!currentState);
interactLocation.getBlock().setBlockData(newState, true);
interactLocation.getBlock().getState().update(true, true);
}
}
else {
Expand All @@ -194,6 +181,23 @@ else if (Depends.citizens != null) {
blockData.setBlock(block.getBlock(), false);
}
else {
// Try for a linked player
if (player == null && Bukkit.getOnlinePlayers().size() > 0) {
// If there's none, link any player
if (Bukkit.getOnlinePlayers().size() > 0) {
player = (Player) Bukkit.getOnlinePlayers().toArray()[0];
}
else if (Depends.citizens != null) {
// If there are no players, link any Human NPC
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.isSpawned() && npc.getEntity() instanceof Player) {
player = (Player) npc.getEntity();
break;
}
}
// TODO: backup if no human NPC available? (Fake EntityPlayer instance?)
}
}
NMSHandler.getInstance().getEntityHelper().forceInteraction(player, interactLocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public PlayerProfile fillPlayerProfile(PlayerProfile playerProfile) {

@Override
public int getPort() {
return ((CraftServer) Bukkit.getServer()).getServer().F();
return ((CraftServer) Bukkit.getServer()).getServer().getPort();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void refreshChunkSections(Chunk chunk) {
if (playerChunk == null) {
return;
}
for (EntityPlayer player : playerChunk.c) {
for (EntityPlayer player : playerChunk.players) {
player.playerConnection.sendPacket(lowPacket);
player.playerConnection.sendPacket(highPacket);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ else if (entity instanceof LivingEntity) {
@Override
public float getBaseYaw(Entity entity) {
net.minecraft.server.v1_13_R2.Entity handle = ((CraftEntity) entity).getHandle();
return ((EntityLiving) handle).aO;
return ((EntityLiving) handle).aR;
}

@Override
Expand All @@ -547,11 +547,11 @@ public void look(Entity entity, float yaw, float pitch) {
while (yaw >= 180.0F) {
yaw -= 360.0F;
}
livingHandle.aO = yaw;
livingHandle.aR = yaw;
if (!(handle instanceof EntityHuman)) {
livingHandle.aN = yaw;
livingHandle.aQ = yaw;
}
livingHandle.aP = yaw;
livingHandle.aS = yaw;
}
handle.pitch = pitch;
}
Expand Down
Loading

0 comments on commit 85e4b77

Please sign in to comment.