Merge branch 'development'

This commit is contained in:
Fernando Pettinelli 2021-12-20 19:37:22 -03:00
commit f57fca41f2
30 changed files with 242 additions and 137 deletions

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../pom.xml</relativePath>
</parent>
@ -365,6 +365,13 @@
<version>4.9.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.decentsoftware-eu</groupId>
<artifactId>decentholograms</artifactId>
<version>2.2.5</version>
<scope>provided</scope>
</dependency>
<!-- End Plugin Hooks -->
<dependency>

View File

@ -53,7 +53,7 @@ public class SongodaCore {
/**
* @since coreRevision 6
*/
private final static String coreVersion = "2.6.8";
private final static String coreVersion = "2.6.9";
/**
* This is specific to the website api

View File

@ -47,21 +47,21 @@ public class HologramManager {
return manager.getCurrentHook();
}
public static void createHologram(Location location, String line) {
public static void createHologram(String id, Location location, String line) {
if (manager.isEnabled()) {
manager.getCurrentHook().createHologram(location, line);
manager.getCurrentHook().createHologram(id, location, line);
}
}
public static void createHologram(Location location, List<String> lines) {
public static void createHologram(String id, Location location, List<String> lines) {
if (manager.isEnabled()) {
manager.getCurrentHook().createHologram(location, lines);
manager.getCurrentHook().createHologram(id, location, lines);
}
}
public static void removeHologram(Location location) {
public static void removeHologram(String id) {
if (manager.isEnabled()) {
manager.getCurrentHook().removeHologram(location);
manager.getCurrentHook().removeHologram(id);
}
}
@ -71,21 +71,29 @@ public class HologramManager {
}
}
public static void updateHologram(Location location, String line) {
public static void updateHologram(String id, String line) {
if (manager.isEnabled()) {
manager.getCurrentHook().updateHologram(location, line);
manager.getCurrentHook().updateHologram(id, line);
}
}
public static void updateHologram(Location location, List<String> lines) {
public static void updateHologram(String id, List<String> lines) {
if (manager.isEnabled()) {
manager.getCurrentHook().updateHologram(location, lines);
manager.getCurrentHook().updateHologram(id, lines);
}
}
public static void bulkUpdateHolograms(Map<Location, List<String>> holograms) {
public static void bulkUpdateHolograms(Map<String, List<String>> holograms) {
if (manager.isEnabled()) {
manager.getCurrentHook().bulkUpdateHolograms(holograms);
}
}
public static boolean isHologramLoaded(String id) {
if (manager.isEnabled()) {
return manager.getCurrentHook().isHologramLoaded(id);
}
return false;
}
}

View File

@ -5,6 +5,7 @@ import com.songoda.core.hooks.economies.PlayerPointsEconomy;
import com.songoda.core.hooks.economies.ReserveEconomy;
import com.songoda.core.hooks.economies.VaultEconomy;
import com.songoda.core.hooks.holograms.CMIHolograms;
import com.songoda.core.hooks.holograms.DecentHologramsHolograms;
import com.songoda.core.hooks.holograms.Holograms;
import com.songoda.core.hooks.holograms.HologramsHolograms;
import com.songoda.core.hooks.holograms.HolographicDisplaysHolograms;
@ -44,6 +45,7 @@ public final class PluginHook<T extends Class> {
public static final PluginHook HOLO_DISPLAYS = new PluginHook(Holograms.class, "HolographicDisplays", HolographicDisplaysHolograms.class);
public static final PluginHook HOLO_HOLOGRAMS = new PluginHook(Holograms.class, "Holograms", HologramsHolograms.class);
public static final PluginHook HOLO_CMI = new PluginHook(Holograms.class, "CMI", CMIHolograms.class);
public static final PluginHook HOLO_DECENTHOLOGRAMS = new PluginHook(Holograms.class, "DecentHolograms", DecentHologramsHolograms.class);
public static final PluginHook LOG_CORE_PROTECT = new PluginHook(Log.class, "CoreProtect", CoreProtectLog.class);
public static final PluginHook PROTECTION_GRIEFPREVENTION = new PluginHook(Protection.class, "GriefPrevention", GriefPreventionProtection.class);
public static final PluginHook PROTECTION_LANDS = new PluginHook(Protection.class, "Lands", LandsProtection.class);

View File

@ -58,15 +58,12 @@ public class CMIHolograms extends Holograms {
}
@Override
public void createHologram(Location location, List<String> lines) {
createAt(fixLocation(location), lines);
public void createHologram(String id, Location location, List<String> lines) {
createAt(id, fixLocation(location), lines);
}
@Override
public void removeHologram(Location location) {
location = fixLocation(location);
final String id = locStr(location);
public void removeHologram(String id) {
CMIHologram holo = cmiHologramManager.getByName(id);
if (holo != null) {
@ -90,9 +87,13 @@ public class CMIHolograms extends Holograms {
}
@Override
public void updateHologram(Location location, List<String> lines) {
location = fixLocation(location);
CMIHologram holo = cmiHologramManager.getByName(locStr(location));
public boolean isHologramLoaded(String id) {
return cmiHologramManager.getByName(id) != null;
}
@Override
public void updateHologram(String id, List<String> lines) {
CMIHologram holo = cmiHologramManager.getByName(id);
if (holo != null) {
// only update if there is a change to the text
@ -123,24 +124,16 @@ public class CMIHolograms extends Holograms {
return;
}
createAt(location, lines);
}
@Override
public void bulkUpdateHolograms(Map<Location, List<String>> hologramData) {
for (Map.Entry<Location, List<String>> entry : hologramData.entrySet()) {
public void bulkUpdateHolograms(Map<String, List<String>> hologramData) {
for (Map.Entry<String, List<String>> entry : hologramData.entrySet()) {
updateHologram(entry.getKey(), entry.getValue());
}
}
private String locStr(Location loc) {
return String.format("%s-%d-%d-%d", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
private void createAt(Location location, List<String> lines) {
final String id = locStr(location);
private void createAt(String id, Location location, List<String> lines) {
CMIHologram holo = new CMIHologram(id, location);
holo.setLines(lines);

View File

@ -0,0 +1,98 @@
package com.songoda.core.hooks.holograms;
import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.DecentHologramsAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DecentHologramsHolograms extends Holograms {
private final Set<String> ourHolograms = new HashSet<>();
public DecentHologramsHolograms(Plugin plugin) {
super(plugin);
}
@Override
public String getName() {
return "DecentHolograms";
}
@Override
public boolean isEnabled() {
return true;
}
@Override
protected double defaultHeightOffset() {
return 1;
}
@Override
public void createHologram(String id, Location location, List<String> lines) {
createAt(id, location, lines);
}
@Override
public void removeHologram(String id) {
Hologram hologram = DHAPI.getHologram(id);
if (hologram != null) {
hologram.delete();
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
}
ourHolograms.remove(id);
}
@Override
public void updateHologram(String id, List<String> lines) {
Hologram hologram = DHAPI.getHologram(id);
if (hologram != null) {
DHAPI.setHologramLines(hologram, lines);
}
}
@Override
public void bulkUpdateHolograms(Map<String, List<String>> hologramData) {
for (Map.Entry<String, List<String>> entry : hologramData.entrySet()) {
updateHologram(entry.getKey(), entry.getValue());
}
}
@Override
public void removeAllHolograms() {
for (String id : ourHolograms) {
Hologram hologram = DHAPI.getHologram(id);
if (hologram != null) {
hologram.delete();
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
}
}
ourHolograms.clear();
}
@Override
public boolean isHologramLoaded(String id) {
return DHAPI.getHologram(id) != null;
}
private void createAt(String id, Location location, List<String> lines) {
location = fixLocation(location);
if (DHAPI.getHologram(id) != null) {
return;
}
DHAPI.createHologram(id, location, lines);
ourHolograms.add(id);
}
}

View File

@ -44,21 +44,23 @@ public abstract class Holograms implements Hook {
protected abstract double defaultHeightOffset();
public void createHologram(Location location, String line) {
createHologram(location, Collections.singletonList(line));
public void createHologram(String id, Location location, String line) {
createHologram(id, location, Collections.singletonList(line));
}
public abstract void createHologram(Location location, List<String> lines);
public abstract void createHologram(String id, Location location, List<String> lines);
public abstract void removeHologram(Location location);
public abstract void removeHologram(String id);
public void updateHologram(Location location, String line) {
updateHologram(location, Collections.singletonList(line));
public void updateHologram(String id, String line) {
updateHologram(id, Collections.singletonList(line));
}
public abstract void updateHologram(Location location, List<String> lines);
public abstract void updateHologram(String id, List<String> lines);
public abstract void bulkUpdateHolograms(Map<Location, List<String>> hologramData);
public abstract void bulkUpdateHolograms(Map<String, List<String>> hologramData);
public abstract void removeAllHolograms();
public abstract boolean isHologramLoaded(String id);
}

View File

@ -11,10 +11,11 @@ import org.bukkit.plugin.Plugin;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class HologramsHolograms extends Holograms {
HologramPlugin hologramPlugin;
HashSet<String> ourHolograms = new HashSet<>();
private final HologramPlugin hologramPlugin;
private final Set<String> ourHolograms = new HashSet<>();
public HologramsHolograms(Plugin plugin) {
super(plugin);
@ -38,15 +39,12 @@ public class HologramsHolograms extends Holograms {
}
@Override
public void createHologram(Location location, List<String> lines) {
createAt(fixLocation(location), lines);
public void createHologram(String id, Location location, List<String> lines) {
createAt(id, fixLocation(location), lines);
}
@Override
public void removeHologram(Location location) {
location = fixLocation(location);
final String id = locStr(location);
public void removeHologram(String id) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
@ -72,9 +70,13 @@ public class HologramsHolograms extends Holograms {
}
@Override
public void updateHologram(Location location, List<String> lines) {
location = fixLocation(location);
Hologram hologram = hologramPlugin.getHologramManager().getHologram(locStr(location));
public boolean isHologramLoaded(String id) {
return hologramPlugin.getHologramManager().getHologram(id) != null;
}
@Override
public void updateHologram(String id, List<String> lines) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
hologram.spawn();
@ -100,24 +102,16 @@ public class HologramsHolograms extends Holograms {
return;
}
createAt(location, lines);
}
@Override
public void bulkUpdateHolograms(Map<Location, List<String>> hologramData) {
for (Map.Entry<Location, List<String>> entry : hologramData.entrySet()) {
public void bulkUpdateHolograms(Map<String, List<String>> hologramData) {
for (Map.Entry<String, List<String>> entry : hologramData.entrySet()) {
updateHologram(entry.getKey(), entry.getValue());
}
}
private String locStr(Location loc) {
return String.format("%s-%d-%d-%d", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
private void createAt(Location location, List<String> lines) {
final String id = locStr(location);
private void createAt(String id, Location location, List<String> lines) {
Hologram hologram = new Hologram(id, location);
for (String line : lines) {

View File

@ -2,17 +2,25 @@ package com.songoda.core.hooks.holograms;
import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HolographicDisplaysHolograms extends Holograms {
private final Map<String, Hologram> holograms = new HashMap<>();
private final String textLineFormat;
public HolographicDisplaysHolograms(Plugin plugin) {
super(plugin);
String version = Bukkit.getPluginManager().getPlugin("HolographicDisplays").getDescription().getVersion();
this.textLineFormat = version.startsWith("3") ? "TextLine{text=%s}" : "CraftTextLine [text=%s]";
}
@Override
@ -31,80 +39,73 @@ public class HolographicDisplaysHolograms extends Holograms {
}
@Override
public void createHologram(Location location, List<String> lines) {
createAt(fixLocation(location), lines);
public void createHologram(String id, Location location, List<String> lines) {
createAt(id, location, lines);
}
@Override
public void removeHologram(Location location) {
location = fixLocation(location);
for (Hologram hologram : HologramsAPI.getHolograms(plugin)) {
if (hologram.getX() != location.getX()
|| hologram.getY() != location.getY()
|| hologram.getZ() != location.getZ()) {
continue;
}
public void removeHologram(String id) {
Hologram hologram = holograms.remove(id);
if (hologram != null) {
hologram.delete();
}
}
@Override
public void updateHologram(Location location, List<String> lines) {
bulkUpdateHolograms(Collections.singletonMap(location, lines));
public void updateHologram(String id, List<String> lines) {
bulkUpdateHolograms(Collections.singletonMap(id, lines));
}
@Override
public void bulkUpdateHolograms(Map<Location, List<String>> hologramData) {
Collection<Hologram> holograms = HologramsAPI.getHolograms(plugin);
for (Map.Entry<Location, List<String>> entry : hologramData.entrySet()) {
Location location = fixLocation(entry.getKey());
public void bulkUpdateHolograms(Map<String, List<String>> hologramData) {
for (Map.Entry<String, List<String>> entry : hologramData.entrySet()) {
String id = entry.getKey();
List<String> lines = entry.getValue();
for (Hologram hologram : holograms) {
if (hologram.getX() != location.getX()
|| hologram.getY() != location.getY()
|| hologram.getZ() != location.getZ()) {
continue;
Hologram hologram = holograms.get(id);
// only update if there is a change to the text
boolean isChanged = lines.size() != hologram.size();
if (!isChanged) {
// double-check the lines
for (int i = 0; !isChanged && i < lines.size(); ++i) {
isChanged = !hologram.getLine(i).toString().equals(String.format(textLineFormat, lines.get(i)));
}
// only update if there is a change to the text
boolean isChanged = lines.size() != hologram.size();
if (!isChanged) {
// double-check the lines
for (int i = 0; !isChanged && i < lines.size(); ++i) {
isChanged = !hologram.getLine(i).toString().equals("CraftTextLine [text=" + lines.get(i) + "]");
}
}
if (isChanged) {
hologram.clearLines();
for (String line : lines) {
hologram.appendTextLine(line);
}
}
return;
}
createAt(location, lines);
if (isChanged) {
hologram.clearLines();
for (String line : lines) {
hologram.appendTextLine(line);
}
}
}
}
private void createAt(Location location, List<String> lines) {
private void createAt(String id, Location location, List<String> lines) {
if (holograms.containsKey(id)) {
return;
}
location = fixLocation(location);
Hologram hologram = HologramsAPI.createHologram(plugin, location);
for (String line : lines) {
hologram.appendTextLine(line);
}
holograms.put(id, hologram);
}
@Override
public void removeAllHolograms() {
HologramsAPI.getHolograms(plugin).forEach(Hologram::delete);
holograms.values().forEach(Hologram::delete);
}
@Override
public boolean isHologramLoaded(String id) {
return holograms.get(id) != null;
}
}

View File

@ -202,9 +202,9 @@ public class ItemUtils {
static Method mc_ItemStack_setTag;
static Method mc_NBTTagCompound_set;
static Method mc_NBTTagCompound_remove;
static Method mc_NBTTagCompound_setShort;
static Method mc_NBTTagCompound_setString;
static Method mc_NBTTagList_add;
// static Method mc_NBTTagCompound_setShort;
// static Method mc_NBTTagCompound_setString;
// static Method mc_NBTTagList_add;
static Method cb_CraftItemStack_asNMSCopy;
static Method cb_CraftItemStack_asCraftMirror;
@ -215,11 +215,11 @@ public class ItemUtils {
mc_ItemStack_setTag = MethodMapping.MC_ITEM_STACK__SET_TAG.getMethod(mc_ItemStack);
mc_NBTTagCompound_set = MethodMapping.MC_NBT_TAG_COMPOUND__SET.getMethod(mc_NBTTagCompound);
mc_NBTTagCompound_remove = MethodMapping.MC_NBT_TAG_COMPOUND__REMOVE.getMethod(mc_NBTTagCompound);
mc_NBTTagCompound_setShort = MethodMapping.MC_NBT_TAG_COMPOUND__SET_SHORT.getMethod(mc_NBTTagCompound);
mc_NBTTagCompound_setString = MethodMapping.MC_NBT_TAG_COMPOUND__SET_STRING.getMethod(mc_NBTTagCompound);
// mc_NBTTagCompound_setShort = MethodMapping.MC_NBT_TAG_COMPOUND__SET_SHORT.getMethod(mc_NBTTagCompound);
// mc_NBTTagCompound_setString = MethodMapping.MC_NBT_TAG_COMPOUND__SET_STRING.getMethod(mc_NBTTagCompound);
cb_CraftItemStack_asNMSCopy = MethodMapping.CB_ITEM_STACK__AS_NMS_COPY.getMethod(cb_ItemStack);
cb_CraftItemStack_asCraftMirror = MethodMapping.CB_ITEM_STACK__AS_CRAFT_MIRROR.getMethod(cb_ItemStack);
mc_NBTTagList_add = MethodMapping.MC_NBT_TAG_LIST__ADD.getMethod(mc_NBTTagList);
// mc_NBTTagList_add = MethodMapping.MC_NBT_TAG_LIST__ADD.getMethod(mc_NBTTagList);
} catch (Exception ex) {
Logger.getLogger(ItemUtils.class.getName()).log(Level.SEVERE, null, ex);
}

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -19,7 +19,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -6,7 +6,7 @@
<groupId>com.songoda</groupId>
<artifactId>SongodaCore-Modules</artifactId>
<version>2.6.8</version>
<version>2.6.9</version>
<packaging>pom</packaging>
<!-- Run 'mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z' to update version recursively -->