This repository was archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Lock editing of individual armor stands #49
Open
dege16
wants to merge
2
commits into
RypoFalem:master
Choose a base branch
from
dege16:patch1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,15 +28,21 @@ | |
import io.github.rypofalem.armorstandeditor.modes.EditMode; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import static jdk.nashorn.internal.objects.NativeObject.keys; | ||
|
||
import net.md_5.bungee.api.ChatMessageType; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.GameMode; | ||
import org.bukkit.Location; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.Sound; | ||
import org.bukkit.entity.ArmorStand; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.persistence.PersistentDataContainer; | ||
import org.bukkit.persistence.PersistentDataType; | ||
import org.bukkit.potion.PotionEffect; | ||
import org.bukkit.potion.PotionEffectType; | ||
import org.bukkit.util.EulerAngle; | ||
|
@@ -102,6 +108,18 @@ public void setCopySlot(byte slot){ | |
public void editArmorStand(ArmorStand armorStand) { | ||
if(!getPlayer().hasPermission("asedit.basic")) return; | ||
armorStand = attemptTarget(armorStand); | ||
|
||
if (eMode == EditMode.LOCK) { | ||
toggleLock(armorStand); | ||
return; | ||
} | ||
|
||
if (isLocked(armorStand)) { | ||
sendMessage("locked", null); | ||
getPlayer().playSound(getPlayer().getLocation(), Sound.BLOCK_CHEST_LOCKED, 1, 1); | ||
return; | ||
} | ||
|
||
switch(eMode){ | ||
case LEFTARM: armorStand.setLeftArmPose(subEulerAngle(armorStand.getLeftArmPose())); | ||
break; | ||
|
@@ -160,6 +178,18 @@ private void openEquipment(ArmorStand armorStand) { | |
public void reverseEditArmorStand(ArmorStand armorStand){ | ||
if(!getPlayer().hasPermission("asedit.basic")) return; | ||
armorStand = attemptTarget(armorStand); | ||
|
||
if (eMode == EditMode.LOCK) { | ||
toggleLock(armorStand); | ||
return; | ||
} | ||
|
||
if (isLocked(armorStand)) { | ||
sendMessage("locked", null); | ||
getPlayer().playSound(getPlayer().getLocation(), Sound.BLOCK_CHEST_LOCKED, 1, 1); | ||
return; | ||
} | ||
|
||
switch(eMode){ | ||
case LEFTARM: armorStand.setLeftArmPose(addEulerAngle(armorStand.getLeftArmPose())); | ||
break; | ||
|
@@ -289,6 +319,27 @@ void cycleAxis(int i) { | |
setAxis(Axis.values()[index]); | ||
} | ||
|
||
void toggleLock(ArmorStand armorStand){ | ||
NamespacedKey key = new NamespacedKey(plugin, "locked"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't recreate NamespacedKey - it's good to keep it in one place |
||
PersistentDataContainer container = armorStand.getPersistentDataContainer(); | ||
if (container.has(key, PersistentDataType.BYTE)) { | ||
container.remove(key); | ||
sendMessage("setlock", "unlocked"); | ||
getPlayer().playSound(getPlayer().getLocation(), Sound.BLOCK_CHEST_OPEN, 1, 1); | ||
} | ||
else { | ||
container.set(key, PersistentDataType.BYTE, (byte)1); | ||
sendMessage("setlock", "locked"); | ||
getPlayer().playSound(getPlayer().getLocation(), Sound.BLOCK_CHEST_CLOSE, 1, 1); | ||
} | ||
} | ||
|
||
boolean isLocked(ArmorStand armorStand) { | ||
NamespacedKey key = new NamespacedKey(plugin, "locked"); | ||
PersistentDataContainer container = armorStand.getPersistentDataContainer(); | ||
return container.has(key, PersistentDataType.BYTE); | ||
} | ||
|
||
private EulerAngle addEulerAngle(EulerAngle angle) { | ||
switch(axis){ | ||
case X: angle = angle.setX(Util.addAngle(angle.getX(), eulerAngleChange)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.bukkit.persistence.PersistentDataContainer; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
//Manages PlayerEditors and Player Events related to editing armorstands | ||
public class PlayerEditorManager implements Listener{ | ||
|
@@ -106,7 +108,18 @@ void onArmorStandInteract(PlayerInteractAtEntityEvent event){ | |
} else { | ||
name = null; | ||
} | ||
|
||
|
||
if (isLocked(as)) { | ||
event.setCancelled(true); | ||
String asName = as.getCustomName(); | ||
boolean asNameVisible = as.isCustomNameVisible(); | ||
Bukkit.getScheduler().runTaskLater(plugin, () -> { | ||
as.setCustomName(asName); | ||
as.setCustomNameVisible(asNameVisible); | ||
}, 1); | ||
Comment on lines
+112
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this trying to do? It seems to do nothing, unless I'm missing some Bukkit quirk? |
||
return; | ||
} | ||
|
||
if(name == null){ | ||
as.setCustomName(null); | ||
as.setCustomNameVisible(false); | ||
|
@@ -196,6 +209,12 @@ boolean canEdit(Player player, ArmorStand as){ | |
ignoreNextInteract = false; | ||
return true; | ||
} | ||
|
||
boolean isLocked(ArmorStand armorStand) { | ||
NamespacedKey key = new NamespacedKey(plugin, "locked"); | ||
PersistentDataContainer container = armorStand.getPersistentDataContainer(); | ||
return container.has(key, PersistentDataType.BYTE); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if duplicating this is needed. Can't the one used above be reused? |
||
|
||
void applyLeftTool(Player player, ArmorStand as){ | ||
getPlayerEditor(player.getUniqueId()).cancelOpenMenu(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it being used or even needed?