1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Double sided sign support. Simplified command recognition on ones

This commit is contained in:
Zrips 2023-11-17 12:37:57 +02:00
parent 6d20ca3d33
commit 527bd03f2f
2 changed files with 41 additions and 11 deletions

View File

@ -226,6 +226,11 @@
<!-- Temporary solution for replacing repository --> <!-- Temporary solution for replacing repository -->
<systemPath>${basedir}/libs/mypet-3.11-20210318.180552-1.jar</systemPath> <systemPath>${basedir}/libs/mypet-3.11-20210318.180552-1.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>CMILib</groupId>
<artifactId>CMILib</artifactId>
<version>1.4.3.1</version>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
<!-- MythicMobs --> <!-- MythicMobs -->

View File

@ -19,6 +19,7 @@
package com.gamingmesh.jobs.listeners; package com.gamingmesh.jobs.listeners;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -83,6 +84,8 @@ import com.gamingmesh.jobs.container.JobsPlayer;
import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIBlock;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Items.ArmorTypes; import net.Zrips.CMILib.Items.ArmorTypes;
import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
@ -216,17 +219,39 @@ public class JobsListener implements Listener {
CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline")))) CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))))
return; return;
String command = CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 1)); List<String> commandLines = new ArrayList<String>();
for (String key : Jobs.getLanguageManager().signKeys) {
if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { if (Version.isCurrentEqualOrHigher(Version.v1_20_R1)) {
command = key; SignSide side = getSignSide(block, player.getLocation());
break; commandLines.addAll(Arrays.asList(sign.getSide(side.equals(SignSide.FRONT) ? org.bukkit.block.sign.Side.FRONT : org.bukkit.block.sign.Side.BACK).getLines()));
} commandLines.remove(0);
} else {
commandLines.addAll(Arrays.asList(sign.getLines()));
commandLines.remove(0);
} }
player.performCommand("jobs " + command + " " + CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 2)) String command = CMIChatColor.stripColor(CMIList.listToString(commandLines, " "));
+ " " + CMIChatColor.stripColor(plugin.getComplement() if (command.endsWith(" "))
.getLine(sign, 3)).replace(" ", "")); // Replace trailing spaces at 3rd line to parse command command = command.substring(0, command.length() - 1);
// Even if we should not cancel in Monitor state, we might add it just in case for the other plugins which could check this event after wards
event.setCancelled(true);
player.performCommand("jobs " + command);
}
public static enum SignSide {
FRONT,
BACK
}
private static SignSide getSignSide(Block sign, Location loc) {
float playerAngle = (float) Math.toDegrees(Math.atan2(loc.getX() - sign.getX() - 0.5, loc.getZ() - sign.getZ() - 0.5));
playerAngle = playerAngle < 0 ? playerAngle + 360 : playerAngle;
BlockFace facing = (new CMIBlock(sign)).getFacing();
double blockAngle = Math.toDegrees(Math.atan2(facing.getModX(), facing.getModZ()));
double phi = Math.abs(blockAngle - playerAngle) % 360;
return (phi > 180 ? 360 - phi : phi) < 90 ? SignSide.FRONT : SignSide.BACK;
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
@ -416,7 +441,7 @@ public class JobsListener implements Listener {
return false; return false;
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onLimitedItemInteract(PlayerInteractEvent event) { public void onLimitedItemInteract(PlayerInteractEvent event) {
@ -486,7 +511,7 @@ public class JobsListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", meinOk)); CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", meinOk));
iih = JobLimitedItems.applyNBT(iih, jobId, itemNode); iih = JobLimitedItems.applyNBT(iih, jobId, itemNode);
try { try {
if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) { if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) {
CMIItemStack.setItemInOffHand(player, iih); CMIItemStack.setItemInOffHand(player, iih);