From 4578f40ffadc4c845b4bc62ad1352cee640d04e8 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Sun, 27 Oct 2019 12:56:25 -0500 Subject: [PATCH 01/27] add block method for compatible material lookup --- .../compatibility/CompatibleMaterial.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index 4c434c3c..e5e9d73b 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -6,6 +6,7 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; @@ -1220,6 +1221,27 @@ public enum CompatibleMaterial { return m != null ? m : lookupMap.get(key + item.getDurability()); } + /** + * Lookup a Material by Block, corrected for legacy + * + * @param block block to check + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(Block block) { + if (block == null) { + return null; + } + Material mat = block.getType(); + if(mat == null) return null; + else if (useLegacy) { + LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name()); + if (legacyBlock != null) { + return lookupMap.get(legacyBlock.name()); + } + } + return lookupMap.get(mat.name()); + } + /** * Lookup a Block Material by its modern id name.
* This also can grab materials by their legacy, but only if there is no From 448a92eebeeae30ef1638e7f88c92060338a29e8 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Sun, 27 Oct 2019 13:11:38 -0500 Subject: [PATCH 02/27] revert 312044c8 - issue was in implementation, not in core --- .../com/songoda/core/compatibility/CompatibleMaterial.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index e5e9d73b..d5b14c5e 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -2138,14 +2138,12 @@ public enum CompatibleMaterial { case BEETROOTS: case CACTUS: case CARROTS: - case CARROT: case CHORUS_FLOWER: // FROSTED_ICE is Ageable, but not a crop case KELP: case MELON_STEM: case NETHER_WART: - case POTATOES: - case POTATO: + case POTATOES: case PUMPKIN_STEM: case SUGAR_CANE: case WHEAT: From 039d73598a0eaeeb1ee59c15f61a12bce7c35ffc Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Sun, 27 Oct 2019 15:52:52 -0500 Subject: [PATCH 03/27] handle comments with newlines as individual lines, add anonymous config --- .../java/com/songoda/core/configuration/Comment.java | 11 ++++------- .../java/com/songoda/core/configuration/Config.java | 7 +++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/configuration/Comment.java b/Core/src/main/java/com/songoda/core/configuration/Comment.java index bbc97482..206471b9 100644 --- a/Core/src/main/java/com/songoda/core/configuration/Comment.java +++ b/Core/src/main/java/com/songoda/core/configuration/Comment.java @@ -23,24 +23,21 @@ public class Comment { } public Comment(String... lines) { - this.lines.addAll(Arrays.asList(lines)); + this(null, Arrays.asList(lines)); } public Comment(List lines) { - if (lines != null) { - this.lines.addAll(lines); - } + this(null, lines); } public Comment(CommentStyle commentStyle, String... lines) { - this.commentStyle = commentStyle; - this.lines.addAll(Arrays.asList(lines)); + this(commentStyle, Arrays.asList(lines)); } public Comment(CommentStyle commentStyle, List lines) { this.commentStyle = commentStyle; if (lines != null) { - this.lines.addAll(lines); + lines.forEach(s -> this.lines.addAll(Arrays.asList(s.split("\n")))); } } diff --git a/Core/src/main/java/com/songoda/core/configuration/Config.java b/Core/src/main/java/com/songoda/core/configuration/Config.java index d7909b19..0cee70c2 100644 --- a/Core/src/main/java/com/songoda/core/configuration/Config.java +++ b/Core/src/main/java/com/songoda/core/configuration/Config.java @@ -109,6 +109,13 @@ public class Config extends ConfigSection { */ int commentSpacing = 1; + public Config() { + this.plugin = null; + this.file = null; + dirName = null; + fileName = null; + } + public Config(@NotNull File file) { this.plugin = null; this.file = file.getAbsoluteFile(); From 5d82f2d55f6b82a3c4e7cb3abe7f9243d43cc6d8 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Sun, 27 Oct 2019 15:53:56 -0500 Subject: [PATCH 04/27] fix yaml lang support, add multiline scalars and a list method --- .../java/com/songoda/core/locale/Locale.java | 122 ++++++++++++------ .../java/com/songoda/core/locale/Message.java | 11 ++ 2 files changed, 92 insertions(+), 41 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/locale/Locale.java b/Core/src/main/java/com/songoda/core/locale/Locale.java index 73fcf37f..cf9da6d6 100644 --- a/Core/src/main/java/com/songoda/core/locale/Locale.java +++ b/Core/src/main/java/com/songoda/core/locale/Locale.java @@ -184,64 +184,70 @@ public class Locale { // Write new changes to existing files, if any at all private static boolean updateFiles(Plugin plugin, InputStream defaultFile, File existingFile, boolean builtin) { - boolean changed = false; - List defaultLines, existingLines; try (BufferedInputStream defaultIn = new BufferedInputStream(defaultFile); BufferedInputStream existingIn = new BufferedInputStream(new FileInputStream(existingFile))) { Charset defaultCharset = TextUtils.detectCharset(defaultIn, StandardCharsets.UTF_8); Charset existingCharset = TextUtils.detectCharset(existingIn, StandardCharsets.UTF_8); - try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(existingFile, true), existingCharset); - BufferedReader defaultReaderOriginal = new BufferedReader(new InputStreamReader(defaultIn, defaultCharset)); + try (BufferedReader defaultReaderOriginal = new BufferedReader(new InputStreamReader(defaultIn, defaultCharset)); BufferedReader existingReaderOriginal = new BufferedReader(new InputStreamReader(existingIn, existingCharset)); BufferedReader defaultReader = translatePropertyToYAML(defaultReaderOriginal, defaultCharset); BufferedReader existingReader = translatePropertyToYAML(existingReaderOriginal, existingCharset);) { - defaultLines = defaultReader.lines().map(s -> s.replaceAll("[\uFEFF\uFFFE\u200B]", "")).collect(Collectors.toList()); - existingLines = existingReader.lines().map(s -> s.replaceAll("[\uFEFF\uFFFE\u200B]", "").split("\\s*=")[0]).collect(Collectors.toList()); - for (String defaultValue : defaultLines) { + Config existingLang = new Config(existingFile); + existingLang.load(existingReader); + translateMsgRoot(existingLang, existingFile, existingCharset); - if (defaultValue.isEmpty() || defaultValue.startsWith("#")) { + Config defaultLang = new Config(); + String defaultData = defaultReader.lines().map(s -> s.replaceAll("[\uFEFF\uFFFE\u200B]", "")).collect(Collectors.joining("\n")); + defaultLang.loadFromString(defaultData); + translateMsgRoot(defaultLang, defaultData, defaultCharset); + + List added = new ArrayList(); + + for (String defaultValueKey : defaultLang.getKeys(true)) { + + Object val = defaultLang.get(defaultValueKey); + if (val instanceof ConfigSection) { continue; } - String key = defaultValue.split("\\s*:")[0]; - - if (!existingLines.contains(key)) { - if (!changed) { - writer.write("\n\n"); - // Leave a note alerting the user of the newly added messages. - writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + "."); - - // If changes were found outside of the default file leave a note explaining that. - if (!builtin) { - writer.write("\n"); - writer.write("# These translations were found untranslated, join\n"); - writer.write("# our translation Discord https://discord.gg/f7fpZEf\n"); - writer.write("# to request an official update!\n"); - } - } - - writer.write("\n"); - - // re-encode to target format? (transform down, not up) -// if (defaultCharset != existingCharset) { -// byte[] encoded = defaultValue.getBytes(defaultCharset); -// defaultValue = new String(encoded, 2, encoded.length - 2, existingCharset); -// } - writer.write(defaultValue); - - changed = true; + if (!existingLang.contains(defaultValueKey)) { + added.add(defaultValueKey); + existingLang.set(defaultValueKey, val); } } + + if (!added.isEmpty()) { + if (!builtin) { + existingLang.setHeader("New messages added for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + ".", + "", + "These translations were found untranslated, join", + "our translation Discord https://discord.gg/f7fpZEf", + "to request an official update!", + "", + added.stream().collect(Collectors.joining("\n")) + ); + } else { + existingLang.setHeader("New messages added for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + ".", + "", + added.stream().collect(Collectors.joining("\n")) + ); + } + existingLang.setRootNodeSpacing(0); + existingLang.save(); + } + return !added.isEmpty(); + } catch (InvalidConfigurationException ex) { + plugin.getLogger().log(Level.SEVERE, "Error checking config " + existingFile.getName(), ex); } } catch (IOException e) { return false; } - return changed; + return false; } /** @@ -271,8 +277,11 @@ public class Locale { Config lang = new Config(file); lang.load(reader); translateMsgRoot(lang, file, charset); - // todo: how should string lists be handled? - lang.getValues(true).forEach((k, v) -> nodes.put(k, v.toString())); + // load lists as strings with newlines + lang.getValues(true).forEach((k, v) -> nodes.put(k, + v instanceof List + ? (((List) v).stream().map(l -> l.toString()).collect(Collectors.joining("\n")).toString()) + : v.toString())); } catch (IOException e) { e.printStackTrace(); return false; @@ -296,9 +305,15 @@ public class Locale { } } Matcher matcher; - if ((line = line.trim().replace('\r', ' ')).isEmpty() || line.startsWith("#") /* Comment */ - || !(matcher = OLD_NODE_PATTERN.matcher(line)).find()) { - output.append(line).append("\n"); + if ((line = line.replace('\r', ' ')).trim().isEmpty() || line.trim().startsWith("#") /* Comment */ + // need to trim the search group because tab characters somehow ended up at the end of lines in a lot of these files + || !(matcher = OLD_NODE_PATTERN.matcher(line.trim())).find()) { + if (line.startsWith("//")) { + // someone used an improper comment in some files *grumble grumble* + output.append("#").append(line).append("\n"); + } else { + output.append(line).append("\n"); + } } else { output.append(matcher.group(1)).append(": \"").append(matcher.group(2)).append("\"\n"); } @@ -333,6 +348,31 @@ public class Locale { } } + protected static void translateMsgRoot(Config lang, String file, Charset charset) throws IOException { + List msgs = lang.getValues(true).entrySet().stream() + .filter(e -> e.getValue() instanceof ConfigSection) + .map(e -> e.getKey()) + .collect(Collectors.toList()); + if (!msgs.isEmpty()) { + String source[] = file.split("\n"); + String line; + for (int lineNumber = 0; lineNumber < source.length; lineNumber++) { + line = source[lineNumber]; + if (lineNumber == 0) { + // remove BOM markers, if any + line = line.replaceAll("[\uFEFF\uFFFE\u200B]", ""); + } + Matcher matcher; + if (!(line = line.trim()).isEmpty() && !line.startsWith("#") + && (matcher = OLD_NODE_PATTERN.matcher(line)).find()) { + if (msgs.contains(matcher.group(1))) { + lang.set(matcher.group(1) + ".message", matcher.group(2)); + } + } + } + } + } + /** * Supply the Message object with the plugins prefix. * diff --git a/Core/src/main/java/com/songoda/core/locale/Message.java b/Core/src/main/java/com/songoda/core/locale/Message.java index 9561441d..8472f4f6 100644 --- a/Core/src/main/java/com/songoda/core/locale/Message.java +++ b/Core/src/main/java/com/songoda/core/locale/Message.java @@ -1,6 +1,8 @@ package com.songoda.core.locale; import com.songoda.core.compatibility.ServerVersion; +import java.util.Arrays; +import java.util.List; import java.util.regex.Matcher; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -126,6 +128,15 @@ public class Message { return ChatColor.translateAlternateColorCodes('&', this.message); } + /** + * Get and format the held message + * + * @return the message + */ + public List getMessageLines() { + return Arrays.asList(ChatColor.translateAlternateColorCodes('&', this.message).split("\n|\\|")); + } + /** * Get the held message * From f522ff1ac9497e01ecdd9ef56ec5f80203f56fd6 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Sun, 27 Oct 2019 15:54:26 -0500 Subject: [PATCH 05/27] version 2.2.7 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc2c7f3d..f0b34429 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.2.6" + version: "2.2.7" build: stage: build From 4eef1c61371fffded3e1f504250ea768a5c432be Mon Sep 17 00:00:00 2001 From: Patryk Bernacki Date: Tue, 29 Oct 2019 13:14:46 +0100 Subject: [PATCH 06/27] Fix drag bug in gui api --- .../java/com/songoda/core/gui/GuiManager.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Core/src/main/java/com/songoda/core/gui/GuiManager.java b/Core/src/main/java/com/songoda/core/gui/GuiManager.java index 8b6513ef..af92f061 100644 --- a/Core/src/main/java/com/songoda/core/gui/GuiManager.java +++ b/Core/src/main/java/com/songoda/core/gui/GuiManager.java @@ -11,6 +11,7 @@ import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -18,6 +19,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.inventory.Inventory; @@ -158,6 +160,25 @@ public class GuiManager { this.manager = manager; } + @EventHandler(priority = EventPriority.LOW) + void onDragGUI(InventoryDragEvent event) { + if (!(event.getWhoClicked() instanceof Player)) { + return; + } + + Inventory openInv = event.getInventory(); + Gui gui; + if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder + && ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) { + gui = ((GuiHolder) openInv.getHolder()).getGUI(); + + if(event.getRawSlots().stream().filter(slot -> gui.inventory.getSize() > slot).anyMatch(slot -> !gui.unlockedCells.getOrDefault(slot, false))){ + event.setCancelled(true); + event.setResult(Result.DENY); + } + } + } + @EventHandler(priority = EventPriority.LOW) void onClickGUI(InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof Player)) { From 336ffe9aecbd1d3a8002b144a5f9b5ade9c15182 Mon Sep 17 00:00:00 2001 From: Brianna Date: Tue, 29 Oct 2019 08:29:44 -0400 Subject: [PATCH 07/27] version 2.2.8 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f0b34429..b925f86c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.2.7" + version: "2.2.8" build: stage: build From aa9ff68b08bb9aaabe3874a09d04b5dbf83ae5b3 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 3 Nov 2019 15:54:17 -0500 Subject: [PATCH 08/27] Remove the dumb semi colons. --- Core/src/main/java/com/songoda/core/locale/Locale.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/songoda/core/locale/Locale.java b/Core/src/main/java/com/songoda/core/locale/Locale.java index cf9da6d6..310dcfc3 100644 --- a/Core/src/main/java/com/songoda/core/locale/Locale.java +++ b/Core/src/main/java/com/songoda/core/locale/Locale.java @@ -304,8 +304,12 @@ public class Locale { output.append(line1.substring(0, line1.length() - line.length())); } } + Matcher matcher; - if ((line = line.replace('\r', ' ')).trim().isEmpty() || line.trim().startsWith("#") /* Comment */ + if ((line = line.replace('\r', ' ') + .replaceAll("\\p{C}", "?") + .replaceAll(";", "")).trim().isEmpty() + || line.trim().startsWith("#") /* Comment */ // need to trim the search group because tab characters somehow ended up at the end of lines in a lot of these files || !(matcher = OLD_NODE_PATTERN.matcher(line.trim())).find()) { if (line.startsWith("//")) { From 8fc955afe9006957e77fd6394b046129b1314c54 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 3 Nov 2019 15:55:19 -0500 Subject: [PATCH 09/27] version 2.2.9 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b925f86c..41dc2dd6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.2.8" + version: "2.2.9" build: stage: build From b86ee7b29dea71e7de88b06df29d88b2d8d7d6ef Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 3 Nov 2019 20:08:48 -0500 Subject: [PATCH 10/27] Save conversions. --- Core/src/main/java/com/songoda/core/configuration/Config.java | 1 + Core/src/main/java/com/songoda/core/locale/Locale.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/configuration/Config.java b/Core/src/main/java/com/songoda/core/configuration/Config.java index 0cee70c2..0a1d0bd6 100644 --- a/Core/src/main/java/com/songoda/core/configuration/Config.java +++ b/Core/src/main/java/com/songoda/core/configuration/Config.java @@ -613,6 +613,7 @@ public class Config extends ConfigSection { } yamlOptions.setIndent(indentation); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + yamlOptions.setSplitLines(false); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); StringWriter str = new StringWriter(); if (headerComment != null) { diff --git a/Core/src/main/java/com/songoda/core/locale/Locale.java b/Core/src/main/java/com/songoda/core/locale/Locale.java index 310dcfc3..6b9c7345 100644 --- a/Core/src/main/java/com/songoda/core/locale/Locale.java +++ b/Core/src/main/java/com/songoda/core/locale/Locale.java @@ -236,9 +236,9 @@ public class Locale { added.stream().collect(Collectors.joining("\n")) ); } - existingLang.setRootNodeSpacing(0); - existingLang.save(); } + existingLang.setRootNodeSpacing(0); + existingLang.save(); return !added.isEmpty(); } catch (InvalidConfigurationException ex) { plugin.getLogger().log(Level.SEVERE, "Error checking config " + existingFile.getName(), ex); From e1054d1299ff9b17118b3d48d0cb7c7d125733ce Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 3 Nov 2019 18:17:23 -0500 Subject: [PATCH 11/27] version 2.2.10 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 41dc2dd6..02f40b26 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.2.9" + version: "2.2.10" build: stage: build From 3754ec7e091fbd6779fad5004b75d9e2313c04d9 Mon Sep 17 00:00:00 2001 From: Patryk Bernacki Date: Wed, 13 Nov 2019 02:52:46 +0100 Subject: [PATCH 12/27] Better .gitignore --- .gitignore | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 203 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 2c4d8e8e..02d235d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,177 @@ +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +### Eclipse Patch ### +# Eclipse Core +.project + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Annotation Processing +.apt_generated + +.sts4-cache/ + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +auto-import. +.idea/modules.xml +.idea/*.iml +.idea/modules +*.iml +*.ipr + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +*.iml +modules.xml +.idea/misc.xml +*.ipr +.idea/compiler.xml + +# Sonarlint plugin +.idea/**/sonarlint/ + +# SonarQube Plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator/ + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Maven ### target/ -.idea/ -songodaUpdater.iml pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup @@ -9,5 +180,33 @@ release.properties dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties -nbactions.xml -nb-configuration.xml +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +### NetBeans ### +**/nbproject/private/ +**/nbproject/Makefile-*.mk +**/nbproject/Package-*.bash +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +### Gradle ### +.gradle + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Gradle Patch ### +**/build/ From 954adf93768f83b8f90bbe0ee972c394f5f9311b Mon Sep 17 00:00:00 2001 From: Patryk Bernacki Date: Wed, 13 Nov 2019 02:53:27 +0100 Subject: [PATCH 13/27] Fix player head api --- .idea/codeStyles/codeStyleConfig.xml | 5 +++ .idea/vcs.xml | 6 +++ .../com/songoda/core/utils/ItemUtils.java | 1 + SongodaCore.iml | 44 ------------------- 4 files changed, 12 insertions(+), 44 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/vcs.xml delete mode 100644 SongodaCore.iml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..b9d18bf5 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java index 512ad573..e32b9de0 100644 --- a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java @@ -257,6 +257,7 @@ public class ItemUtils { } else { meta.setOwner(player.getName()); } + head.setItemMeta(meta); return head; } diff --git a/SongodaCore.iml b/SongodaCore.iml deleted file mode 100644 index 000b875c..00000000 --- a/SongodaCore.iml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 1beb3848f8b869412d4254815580922bdcfdb5aa Mon Sep 17 00:00:00 2001 From: Patryk Bernacki Date: Wed, 13 Nov 2019 02:57:35 +0100 Subject: [PATCH 14/27] Fix dependency issue (WildStacker) --- Core/pom.xml | 34 +++++++++++++++++++++++++++++++--- pom.xml | 4 ++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Core/pom.xml b/Core/pom.xml index 04b9827b..ef0967ea 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -27,6 +27,34 @@ 1.8 + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + none + + + + attach-javadocs + + jar + + + + org.apache.maven.plugins maven-shade-plugin @@ -251,9 +279,9 @@ provided - com.bgsoftware - WildStacker - 2-9-0 + com.github.OmerBenGera + WildStackerAPI + b16 provided diff --git a/pom.xml b/pom.xml index b42ccf44..96a9a46f 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + jitpack.io + https://jitpack.io + From 443e3b01364a1f950d6cf47ff4d654161c561495 Mon Sep 17 00:00:00 2001 From: Patryk Bernacki Date: Wed, 13 Nov 2019 03:03:14 +0100 Subject: [PATCH 15/27] version 2.2.11 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 02f40b26..96fa6672 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.2.10" + version: "2.2.11" build: stage: build From 7ae9469eb716386320eefb671e81cdf047af7fd0 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 8 Dec 2019 17:04:53 -0500 Subject: [PATCH 16/27] added some missing blocks. --- .../com/songoda/core/compatibility/CompatibleMaterial.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index d5b14c5e..da63007b 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -348,7 +348,7 @@ public enum CompatibleMaterial { END_PORTAL_FRAME("ENDER_PORTAL_FRAME"), END_ROD, END_STONE("ENDER_STONE"), - END_STONE_BRICKS, + END_STONE_BRICKS("END_BRICKS"), END_STONE_BRICK_SLAB(), END_STONE_BRICK_STAIRS, END_STONE_BRICK_WALL, @@ -617,7 +617,7 @@ public enum CompatibleMaterial { NETHERRACK, NETHER_BRICK("NETHER_BRICK_ITEM"), NETHER_BRICKS("NETHER_BRICK"), - NETHER_BRICK_FENCE(), + NETHER_BRICK_FENCE("NETHER_FENCE"), NETHER_BRICK_SLAB("STEP", (byte) 6), NETHER_BRICK_STAIRS, NETHER_BRICK_WALL, From 163f4cd95009a221c9d74bff1675f5954329af5a Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 8 Dec 2019 17:38:43 -0500 Subject: [PATCH 17/27] version 2.2.12 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 96fa6672..729b0b66 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.2.11" + version: "2.2.12" build: stage: build From bceb1c906373e392bc49dde00a7f7725aeca49f3 Mon Sep 17 00:00:00 2001 From: Brianna Date: Wed, 11 Dec 2019 14:22:01 -0500 Subject: [PATCH 18/27] Beta 1.15 Support (Waiting on Paper) --- Core/pom.xml | 14 +- .../songoda/core/commands/CommandManager.java | 2 +- .../compatibility/CompatibleMaterial.java | 10 + .../CompatibleParticleHandler.java | 55 +- .../core/compatibility/CompatibleSound.java | 23 + .../java/com/songoda/core/nms/NmsManager.java | 2 + .../com/songoda/core/utils/ItemUtils.java | 2 - .../nms/v1_14_R1/AnvilInventoryCustom.java | 44 +- .../songoda/core/nms/v1_14_R1/AnvilView.java | 522 +++++++++--------- .../com/songoda/core/nms/v1_14_R1/NMS.java | 48 +- NMS/NMS-v1_15_R1/pom.xml | 28 + .../nms/v1_15_R1/AnvilInventoryCustom.java | 22 + .../songoda/core/nms/v1_15_R1/AnvilView.java | 261 +++++++++ .../com/songoda/core/nms/v1_15_R1/NMS.java | 24 + pom.xml | 1 + 15 files changed, 720 insertions(+), 338 deletions(-) create mode 100644 NMS/NMS-v1_15_R1/pom.xml create mode 100644 NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilInventoryCustom.java create mode 100644 NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilView.java create mode 100644 NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/NMS.java diff --git a/Core/pom.xml b/Core/pom.xml index ef0967ea..0a0a5fb3 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -114,10 +114,9 @@ - com.destroystokyo.papermc - paper - 1.14.4 - provided + org.spigotmc + spigot + 1.15 diff --git a/Core/src/main/java/com/songoda/core/commands/CommandManager.java b/Core/src/main/java/com/songoda/core/commands/CommandManager.java index 127c0afc..ef8e1626 100644 --- a/Core/src/main/java/com/songoda/core/commands/CommandManager.java +++ b/Core/src/main/java/com/songoda/core/commands/CommandManager.java @@ -315,7 +315,7 @@ public class CommandManager implements CommandExecutor, TabCompleter { // If we're on Paper 1.8, we need to register timings (spigot creates timings on init, paper creates it on register) // later versions of paper create timings if needed when the command is executed if (ServerProject.isServer(ServerProject.PAPER, ServerProject.TACO) && ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) { - commandObject.timings = co.aikar.timings.TimingsManager.getCommandTiming(plugin.getName().toLowerCase(), commandObject); + // commandObject.timings = co.aikar.timings.TimingsManager.getCommandTiming(plugin.getName().toLowerCase(), commandObject); } // Set command action diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index da63007b..7abfff2f 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -30,6 +30,16 @@ public enum CompatibleMaterial { DARK_OAK_DOOR_ITEM(431), */ + + /* 1.15 */ + BEE_SPAWN_EGG(), + BEE_NEST(), + BEEHIVE(), + HONEY_BLOCK(), + HONEY_BOTTLE(), + HONEYCOMB(), + HONEYCOMB_BLOCK(), + ACACIA_BOAT("BOAT_ACACIA"), ACACIA_BUTTON(), ACACIA_DOOR("ACACIA_DOOR_ITEM"), diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java index 58a35bfa..708a171d 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java @@ -1,17 +1,24 @@ package com.songoda.core.compatibility; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; import org.bukkit.Color; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.block.BlockFace; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + public class CompatibleParticleHandler { public static enum ParticleType { + /* 1.15 */ + DRIPPING_HONEY, + FALLING_HONEY, + FALLING_NECTAR, + LANDING_HONEY, + EXPLOSION_NORMAL(), EXPLOSION_LARGE, EXPLOSION_HUGE, @@ -214,17 +221,17 @@ public class CompatibleParticleHandler { public static void redstoneParticles(Location location, int red, int green, int blue) { redstoneParticles(location, red, green, blue, 1F, 1, 0); } - + /** * Spawn colored redstone particles - * + * * @param location area to spawn the particle in - * @param red red value 0-255 - * @param green green value 0-255 - * @param blue blue value 0-255 - * @param size (1.13+) size of the particles - * @param count how many particles to spawn - * @param radius how far to spread out the particles from location + * @param red red value 0-255 + * @param green green value 0-255 + * @param blue blue value 0-255 + * @param size (1.13+) size of the particles + * @param count how many particles to spawn + * @param radius how far to spread out the particles from location */ public static void redstoneParticles(Location location, int red, int green, int blue, float size, int count, float radius) { if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { @@ -247,23 +254,23 @@ public class CompatibleParticleHandler { float yy = (float) (radius * (Math.random() - Math.random())); float zz = (float) (radius * (Math.random() - Math.random())); Location at = location.clone().add(xx, yy, zz); - LegacyParticleEffects.createParticle(at, LegacyParticleEffects.Type.REDSTONE, + LegacyParticleEffects.createParticle(at, LegacyParticleEffects.Type.REDSTONE, red / 255F, green / 255F, blue / 255F, 1F, 0, null); } } } - public static void bonemealSmoke(Location l) { - final org.bukkit.World w = l.getWorld(); - w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH_EAST); - w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH); - w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH_WEST); - w.playEffect(l, Effect.SMOKE, BlockFace.EAST); - w.playEffect(l, Effect.SMOKE, BlockFace.SELF); - w.playEffect(l, Effect.SMOKE, BlockFace.WEST); - w.playEffect(l, Effect.SMOKE, BlockFace.NORTH_EAST); - w.playEffect(l, Effect.SMOKE, BlockFace.NORTH); - w.playEffect(l, Effect.SMOKE, BlockFace.NORTH_WEST); - } + public static void bonemealSmoke(Location l) { + final org.bukkit.World w = l.getWorld(); + w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH_EAST); + w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH); + w.playEffect(l, Effect.SMOKE, BlockFace.SOUTH_WEST); + w.playEffect(l, Effect.SMOKE, BlockFace.EAST); + w.playEffect(l, Effect.SMOKE, BlockFace.SELF); + w.playEffect(l, Effect.SMOKE, BlockFace.WEST); + w.playEffect(l, Effect.SMOKE, BlockFace.NORTH_EAST); + w.playEffect(l, Effect.SMOKE, BlockFace.NORTH); + w.playEffect(l, Effect.SMOKE, BlockFace.NORTH_WEST); + } } diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleSound.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleSound.java index 630fa5d5..0cb6762a 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleSound.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleSound.java @@ -23,6 +23,29 @@ public enum CompatibleSound { // would using the raw strings be better? // 1.8 list: // https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/mapping-and-modding-tutorials/2213619-1-8-all-playsound-sound-arguments + + /* 1.15 */ + BLOCK_BEEHIVE_DRIP, + BLOCK_BEEHIVE_ENTER, + BLOCK_BEEHIVE_EXIT, + BLOCK_BEEHIVE_SHEAR, + BLOCK_BEEHIVE_WORK, + BLOCK_HONEY_BLOCK_BREAK, + BLOCK_HONEY_BLOCK_FALL, + BLOCK_HONEY_BLOCK_HIT, + BLOCK_HONEY_BLOCK_PLACE, + BLOCK_HONEY_BLOCK_SLIDE, + BLOCK_HONEY_BLOCK_STEP, + ENTITY_BEE_DEATH, + ENTITY_BEE_HURT, + ENTITY_BEE_LOOP, + ENTITY_BEE_LOOP_AGGRESSIVE, + ENTITY_BEE_POLLINATE, + ENTITY_BEE_STING, + ENTITY_IRON_GOLEM_DAMAGE, + ENTITY_IRON_GOLEM_REPAIR, + ITEM_HONEY_BOTTLE_DRINK, + AMBIENT_CAVE(ServerVersion.V1_9, v("AMBIENCE_CAVE")), AMBIENT_UNDERWATER_ENTER, AMBIENT_UNDERWATER_EXIT, diff --git a/Core/src/main/java/com/songoda/core/nms/NmsManager.java b/Core/src/main/java/com/songoda/core/nms/NmsManager.java index e0fec81b..d7fe0795 100644 --- a/Core/src/main/java/com/songoda/core/nms/NmsManager.java +++ b/Core/src/main/java/com/songoda/core/nms/NmsManager.java @@ -40,6 +40,8 @@ public class NmsManager { return new com.songoda.core.nms.v1_13_R2.NMS(); case "v1_14_R1": return new com.songoda.core.nms.v1_14_R1.NMS(); + case "v1_15_R1": + return new com.songoda.core.nms.v1_15_R1.NMS(); } Logger.getLogger(NmsManager.class.getName()).log(Level.SEVERE, "Failed to load NMS for this server version: version {0} not found", serverPackageVersion); return null; diff --git a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java index e32b9de0..5b3c6d72 100644 --- a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java @@ -46,8 +46,6 @@ public class ItemUtils { public static String getItemName(ItemStack it) { if (it == null) { return null; - } else if (can_getI18NDisplayName) { - return it.getI18NDisplayName(); } else { return itemName(it.getType()); } diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilInventoryCustom.java b/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilInventoryCustom.java index bd55fdea..d1b112d4 100644 --- a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilInventoryCustom.java +++ b/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilInventoryCustom.java @@ -1,22 +1,22 @@ -package com.songoda.core.nms.v1_14_R1; - -import net.minecraft.server.v1_14_R1.ContainerAnvil; -import net.minecraft.server.v1_14_R1.IInventory; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryAnvil; -import org.bukkit.inventory.InventoryHolder; - -public class AnvilInventoryCustom extends CraftInventoryAnvil { - - final InventoryHolder holder; - - public AnvilInventoryCustom(InventoryHolder holder, Location location, IInventory inventory, IInventory resultInventory, ContainerAnvil container) { - super(location, inventory, resultInventory, container); - this.holder = holder; - } - - @Override - public InventoryHolder getHolder() { - return holder; - } -} +package com.songoda.core.nms.v1_14_R1; + +import net.minecraft.server.v1_14_R1.ContainerAnvil; +import net.minecraft.server.v1_14_R1.IInventory; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryAnvil; +import org.bukkit.inventory.InventoryHolder; + +public class AnvilInventoryCustom extends CraftInventoryAnvil { + + final InventoryHolder holder; + + public AnvilInventoryCustom(InventoryHolder holder, Location location, IInventory inventory, IInventory resultInventory, ContainerAnvil container) { + super(location, inventory, resultInventory, container); + this.holder = holder; + } + + @Override + public InventoryHolder getHolder() { + return holder; + } +} diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilView.java b/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilView.java index 99c98206..e89f2b65 100644 --- a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilView.java +++ b/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/AnvilView.java @@ -1,261 +1,261 @@ -package com.songoda.core.nms.v1_14_R1; - -import com.songoda.core.nms.CustomAnvil; -import com.songoda.core.nms.methods.AnvilTextChange; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.minecraft.server.v1_14_R1.BlockPosition; -import net.minecraft.server.v1_14_R1.ChatMessage; -import net.minecraft.server.v1_14_R1.Container; -import net.minecraft.server.v1_14_R1.ContainerAccess; -import net.minecraft.server.v1_14_R1.ContainerAnvil; -import net.minecraft.server.v1_14_R1.ContainerProperty; -import net.minecraft.server.v1_14_R1.Containers; -import net.minecraft.server.v1_14_R1.EntityHuman; -import net.minecraft.server.v1_14_R1.EntityPlayer; -import net.minecraft.server.v1_14_R1.IInventory; -import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; - -public class AnvilView extends ContainerAnvil implements CustomAnvil { - - private final EntityPlayer entity; - private final Inventory inventory; - private String customTitle = "Repairing"; - private int cost = -1; - private boolean canUse = true; - private AnvilTextChange textChange = null; - - // used for setting custom inventory - static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result - static Field mc_ContainerAnvil_resultInventory; // full inventory - static Field mc_ContainerAnvil_bukkitEntity; - - static { - try { - mc_ContainerAnvil_repairInventory = ContainerAnvil.class.getDeclaredField("repairInventory"); - mc_ContainerAnvil_repairInventory.setAccessible(true); - mc_ContainerAnvil_resultInventory = ContainerAnvil.class.getDeclaredField("resultInventory"); - mc_ContainerAnvil_resultInventory.setAccessible(true); - mc_ContainerAnvil_bukkitEntity = ContainerAnvil.class.getDeclaredField("bukkitEntity"); - mc_ContainerAnvil_bukkitEntity.setAccessible(true); - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); - } - } - - // 1.14.3 and 1.14.4 have different fields for levelCost - static boolean compat_mode = true; - static Method mc_ContainerProperty_set; - static Method mc_ContainerProperty_get; - // 1.14 also made this field private. Fun. - static Field mc_Container_windowId; - // 1.14 also introduced a title field, also private, which can only be set once and can't be checked - static Field mc_Container_title; - - static { - try { - mc_Container_windowId = Container.class.getDeclaredField("windowId"); - mc_Container_windowId.setAccessible(true); - mc_Container_title = Container.class.getDeclaredField("title"); - mc_Container_title.setAccessible(true); - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); - } - for (Method m : ContainerProperty.class.getMethods()) { - if (m.getName().equals("set")) { - compat_mode = false; - break; - } - } - if (compat_mode) { - try { - mc_ContainerProperty_set = ContainerProperty.class.getDeclaredMethod("a", int.class); - mc_ContainerProperty_get = ContainerProperty.class.getDeclaredMethod("b"); - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); - } - } - } - - public AnvilView(int id, EntityPlayer entity, InventoryHolder holder) { - super(id, entity.inventory, ContainerAccess.at(entity.world, new BlockPosition(0, 0, 0))); - this.setTitle(new ChatMessage(customTitle != null ? customTitle : "")); - this.checkReachable = false; - this.entity = entity; - if(holder != null) { - this.inventory = getBukkitView(entity, holder).getTopInventory(); - } else { - this.inventory = getBukkitView().getTopInventory(); - } - } - - public CraftInventoryView getBukkitView(EntityHuman player, InventoryHolder holder) { - try { - AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder, - new Location(entity.world.getWorld(), 0, 0, 0), - (IInventory) mc_ContainerAnvil_repairInventory.get(this), - (IInventory) mc_ContainerAnvil_resultInventory.get(this), this); - CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this); - mc_ContainerAnvil_bukkitEntity.set(this, view); - return view; - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); - } - return getBukkitView(); - } - - @Override - public boolean canUse(EntityHuman entityhuman) { - return canUse; - } - - @Override - public void e() { - super.e(); - if (cost >= 0) { - if (compat_mode) { - if (mc_ContainerProperty_set != null) { - try { - mc_ContainerProperty_set.invoke(this.levelCost, 0); - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); - mc_ContainerProperty_set = null; - } - } - } else { - this.levelCost.set(cost); - } - } - textChange.onChange(); - } - - @Override - public void update() { - e(); - } - - @Override - public String getRenameText() { - return this.renameText; - } - - @Override - public void setRenameText(String text) { - this.a(text); - } - - @Override - public void setOnChange(AnvilTextChange handler) { - textChange = handler; - } - - @Override - public String getCustomTitle() { - return customTitle; - } - - @Override - public void setCustomTitle(String title) { - this.customTitle = title; - try { - mc_Container_title.set(this, new ChatMessage(customTitle != null ? customTitle : "")); - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); - } - } - - @Override - public void setLevelCost(int cost) { - this.cost = cost; - } - - @Override - public int getLevelCost() { - if (cost >= 0) { - return cost; - } else if (compat_mode) { - if (mc_ContainerProperty_get != null) { - try { - return (int) mc_ContainerProperty_get.invoke(this.levelCost); - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); - mc_ContainerProperty_get = null; - } - } - } else { - return this.levelCost.get(); - } - return -1; - } - - @Override - public void setCanUse(boolean bool) { - this.canUse = bool; - } - - @Override - public ItemStack getLeftInput() { - return inventory.getItem(0); - } - - @Override - public ItemStack getRightInput() { - return inventory.getItem(1); - } - - @Override - public ItemStack getOutput() { - return inventory.getItem(2); - } - - @Override - public void setLeftInput(ItemStack item) { - inventory.setItem(0, item); - } - - @Override - public void setRightInput(ItemStack item) { - inventory.setItem(1, item); - } - - @Override - public void setOutput(ItemStack item) { - inventory.setItem(2, item); - } - - @Override - public Inventory getInventory() { - return inventory; - } - - @Override - public void open() { - - // Counter stuff that the game uses to keep track of inventories - int id = entity.nextContainerCounter(); - - // Send the packet - entity.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, new ChatMessage(customTitle != null ? customTitle : ""))); - - // Set their active container to this anvil - entity.activeContainer = this; - - try { - // Set their active container window id to that counter stuff - mc_Container_windowId.set(this, id); - } catch (Exception ex) { - Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Create Error", ex); - } - - // Add the slot listener - entity.activeContainer.addSlotListener(entity); - } - -} +package com.songoda.core.nms.v1_14_R1; + +import com.songoda.core.nms.CustomAnvil; +import com.songoda.core.nms.methods.AnvilTextChange; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.minecraft.server.v1_14_R1.BlockPosition; +import net.minecraft.server.v1_14_R1.ChatMessage; +import net.minecraft.server.v1_14_R1.Container; +import net.minecraft.server.v1_14_R1.ContainerAccess; +import net.minecraft.server.v1_14_R1.ContainerAnvil; +import net.minecraft.server.v1_14_R1.ContainerProperty; +import net.minecraft.server.v1_14_R1.Containers; +import net.minecraft.server.v1_14_R1.EntityHuman; +import net.minecraft.server.v1_14_R1.EntityPlayer; +import net.minecraft.server.v1_14_R1.IInventory; +import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; + +public class AnvilView extends ContainerAnvil implements CustomAnvil { + + private final EntityPlayer entity; + private final Inventory inventory; + private String customTitle = "Repairing"; + private int cost = -1; + private boolean canUse = true; + private AnvilTextChange textChange = null; + + // used for setting custom inventory + static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result + static Field mc_ContainerAnvil_resultInventory; // full inventory + static Field mc_ContainerAnvil_bukkitEntity; + + static { + try { + mc_ContainerAnvil_repairInventory = ContainerAnvil.class.getDeclaredField("repairInventory"); + mc_ContainerAnvil_repairInventory.setAccessible(true); + mc_ContainerAnvil_resultInventory = ContainerAnvil.class.getDeclaredField("resultInventory"); + mc_ContainerAnvil_resultInventory.setAccessible(true); + mc_ContainerAnvil_bukkitEntity = ContainerAnvil.class.getDeclaredField("bukkitEntity"); + mc_ContainerAnvil_bukkitEntity.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + + // 1.14.3 and 1.14.4 have different fields for levelCost + static boolean compat_mode = true; + static Method mc_ContainerProperty_set; + static Method mc_ContainerProperty_get; + // 1.14 also made this field private. Fun. + static Field mc_Container_windowId; + // 1.14 also introduced a title field, also private, which can only be set once and can't be checked + static Field mc_Container_title; + + static { + try { + mc_Container_windowId = Container.class.getDeclaredField("windowId"); + mc_Container_windowId.setAccessible(true); + mc_Container_title = Container.class.getDeclaredField("title"); + mc_Container_title.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + for (Method m : ContainerProperty.class.getMethods()) { + if (m.getName().equals("set")) { + compat_mode = false; + break; + } + } + if (compat_mode) { + try { + mc_ContainerProperty_set = ContainerProperty.class.getDeclaredMethod("a", int.class); + mc_ContainerProperty_get = ContainerProperty.class.getDeclaredMethod("b"); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + } + + public AnvilView(int id, EntityPlayer entity, InventoryHolder holder) { + super(id, entity.inventory, ContainerAccess.at(entity.world, new BlockPosition(0, 0, 0))); + this.setTitle(new ChatMessage(customTitle != null ? customTitle : "")); + this.checkReachable = false; + this.entity = entity; + if(holder != null) { + this.inventory = getBukkitView(entity, holder).getTopInventory(); + } else { + this.inventory = getBukkitView().getTopInventory(); + } + } + + public CraftInventoryView getBukkitView(EntityHuman player, InventoryHolder holder) { + try { + AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder, + new Location(entity.world.getWorld(), 0, 0, 0), + (IInventory) mc_ContainerAnvil_repairInventory.get(this), + (IInventory) mc_ContainerAnvil_resultInventory.get(this), this); + CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this); + mc_ContainerAnvil_bukkitEntity.set(this, view); + return view; + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + return getBukkitView(); + } + + @Override + public boolean canUse(EntityHuman entityhuman) { + return canUse; + } + + @Override + public void e() { + super.e(); + if (cost >= 0) { + if (compat_mode) { + if (mc_ContainerProperty_set != null) { + try { + mc_ContainerProperty_set.invoke(this.levelCost, 0); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + mc_ContainerProperty_set = null; + } + } + } else { + this.levelCost.set(cost); + } + } + textChange.onChange(); + } + + @Override + public void update() { + e(); + } + + @Override + public String getRenameText() { + return this.renameText; + } + + @Override + public void setRenameText(String text) { + this.a(text); + } + + @Override + public void setOnChange(AnvilTextChange handler) { + textChange = handler; + } + + @Override + public String getCustomTitle() { + return customTitle; + } + + @Override + public void setCustomTitle(String title) { + this.customTitle = title; + try { + mc_Container_title.set(this, new ChatMessage(customTitle != null ? customTitle : "")); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + } + } + + @Override + public void setLevelCost(int cost) { + this.cost = cost; + } + + @Override + public int getLevelCost() { + if (cost >= 0) { + return cost; + } else if (compat_mode) { + if (mc_ContainerProperty_get != null) { + try { + return (int) mc_ContainerProperty_get.invoke(this.levelCost); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + mc_ContainerProperty_get = null; + } + } + } else { + return this.levelCost.get(); + } + return -1; + } + + @Override + public void setCanUse(boolean bool) { + this.canUse = bool; + } + + @Override + public ItemStack getLeftInput() { + return inventory.getItem(0); + } + + @Override + public ItemStack getRightInput() { + return inventory.getItem(1); + } + + @Override + public ItemStack getOutput() { + return inventory.getItem(2); + } + + @Override + public void setLeftInput(ItemStack item) { + inventory.setItem(0, item); + } + + @Override + public void setRightInput(ItemStack item) { + inventory.setItem(1, item); + } + + @Override + public void setOutput(ItemStack item) { + inventory.setItem(2, item); + } + + @Override + public Inventory getInventory() { + return inventory; + } + + @Override + public void open() { + + // Counter stuff that the game uses to keep track of inventories + int id = entity.nextContainerCounter(); + + // Send the packet + entity.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, new ChatMessage(customTitle != null ? customTitle : ""))); + + // Set their active container to this anvil + entity.activeContainer = this; + + try { + // Set their active container window id to that counter stuff + mc_Container_windowId.set(this, id); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Create Error", ex); + } + + // Add the slot listener + entity.activeContainer.addSlotListener(entity); + } + +} diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/NMS.java b/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/NMS.java index fdb8756d..499cc38c 100644 --- a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/NMS.java +++ b/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/NMS.java @@ -1,24 +1,24 @@ -package com.songoda.core.nms.v1_14_R1; - -import com.songoda.core.nms.CoreNMS; -import com.songoda.core.nms.CustomAnvil; -import net.minecraft.server.v1_14_R1.EntityPlayer; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.inventory.InventoryHolder; - -public class NMS implements CoreNMS { - - @Override - public CustomAnvil createAnvil(Player player) { - EntityPlayer p = ((CraftPlayer) player).getHandle(); - return new AnvilView(p.nextContainerCounter(), p, null); - } - - @Override - public CustomAnvil createAnvil(Player player, InventoryHolder holder) { - EntityPlayer p = ((CraftPlayer) player).getHandle(); - return new AnvilView(p.nextContainerCounter(), p, holder); - } - -} +package com.songoda.core.nms.v1_14_R1; + +import com.songoda.core.nms.CoreNMS; +import com.songoda.core.nms.CustomAnvil; +import net.minecraft.server.v1_14_R1.EntityPlayer; +import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryHolder; + +public class NMS implements CoreNMS { + + @Override + public CustomAnvil createAnvil(Player player) { + EntityPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, null); + } + + @Override + public CustomAnvil createAnvil(Player player, InventoryHolder holder) { + EntityPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, holder); + } + +} diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml new file mode 100644 index 00000000..b56e44d7 --- /dev/null +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -0,0 +1,28 @@ + + + + com.songoda + SongodaCore-Modules + maven-version-number + ../../ + + + SongodaCore-NMS-v1_15_R1 + + 4.0.0 + jar + + + + org.spigotmc + spigot + 1.15 + + + com.songoda + SongodaCore-NMS-API + ${project.version} + provided + + + \ No newline at end of file diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilInventoryCustom.java b/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilInventoryCustom.java new file mode 100644 index 00000000..3f3d69c4 --- /dev/null +++ b/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilInventoryCustom.java @@ -0,0 +1,22 @@ +package com.songoda.core.nms.v1_15_R1; + +import net.minecraft.server.v1_15_R1.ContainerAnvil; +import net.minecraft.server.v1_15_R1.IInventory; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryAnvil; +import org.bukkit.inventory.InventoryHolder; + +public class AnvilInventoryCustom extends CraftInventoryAnvil { + + final InventoryHolder holder; + + public AnvilInventoryCustom(InventoryHolder holder, Location location, IInventory inventory, IInventory resultInventory, ContainerAnvil container) { + super(location, inventory, resultInventory, container); + this.holder = holder; + } + + @Override + public InventoryHolder getHolder() { + return holder; + } +} diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilView.java b/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilView.java new file mode 100644 index 00000000..581f172f --- /dev/null +++ b/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/AnvilView.java @@ -0,0 +1,261 @@ +package com.songoda.core.nms.v1_15_R1; + +import com.songoda.core.nms.CustomAnvil; +import com.songoda.core.nms.methods.AnvilTextChange; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.minecraft.server.v1_15_R1.BlockPosition; +import net.minecraft.server.v1_15_R1.ChatMessage; +import net.minecraft.server.v1_15_R1.Container; +import net.minecraft.server.v1_15_R1.ContainerAccess; +import net.minecraft.server.v1_15_R1.ContainerAnvil; +import net.minecraft.server.v1_15_R1.ContainerProperty; +import net.minecraft.server.v1_15_R1.Containers; +import net.minecraft.server.v1_15_R1.EntityHuman; +import net.minecraft.server.v1_15_R1.EntityPlayer; +import net.minecraft.server.v1_15_R1.IInventory; +import net.minecraft.server.v1_15_R1.PacketPlayOutOpenWindow; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; + +public class AnvilView extends ContainerAnvil implements CustomAnvil { + + private final EntityPlayer entity; + private final Inventory inventory; + private String customTitle = "Repairing"; + private int cost = -1; + private boolean canUse = true; + private AnvilTextChange textChange = null; + + // used for setting custom inventory + static Field mc_ContainerAnvil_repairInventory; // subcontainer with only the result + static Field mc_ContainerAnvil_resultInventory; // full inventory + static Field mc_ContainerAnvil_bukkitEntity; + + static { + try { + mc_ContainerAnvil_repairInventory = ContainerAnvil.class.getDeclaredField("repairInventory"); + mc_ContainerAnvil_repairInventory.setAccessible(true); + mc_ContainerAnvil_resultInventory = ContainerAnvil.class.getDeclaredField("resultInventory"); + mc_ContainerAnvil_resultInventory.setAccessible(true); + mc_ContainerAnvil_bukkitEntity = ContainerAnvil.class.getDeclaredField("bukkitEntity"); + mc_ContainerAnvil_bukkitEntity.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + + // 1.14.3 and 1.14.4 have different fields for levelCost + static boolean compat_mode = true; + static Method mc_ContainerProperty_set; + static Method mc_ContainerProperty_get; + // 1.14 also made this field private. Fun. + static Field mc_Container_windowId; + // 1.14 also introduced a title field, also private, which can only be set once and can't be checked + static Field mc_Container_title; + + static { + try { + mc_Container_windowId = Container.class.getDeclaredField("windowId"); + mc_Container_windowId.setAccessible(true); + mc_Container_title = Container.class.getDeclaredField("title"); + mc_Container_title.setAccessible(true); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + for (Method m : ContainerProperty.class.getMethods()) { + if (m.getName().equals("set")) { + compat_mode = false; + break; + } + } + if (compat_mode) { + try { + mc_ContainerProperty_set = ContainerProperty.class.getDeclaredMethod("a", int.class); + mc_ContainerProperty_get = ContainerProperty.class.getDeclaredMethod("b"); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + } + } + + public AnvilView(int id, EntityPlayer entity, InventoryHolder holder) { + super(id, entity.inventory, ContainerAccess.at(entity.world, new BlockPosition(0, 0, 0))); + this.setTitle(new ChatMessage(customTitle != null ? customTitle : "")); + this.checkReachable = false; + this.entity = entity; + if(holder != null) { + this.inventory = getBukkitView(entity, holder).getTopInventory(); + } else { + this.inventory = getBukkitView().getTopInventory(); + } + } + + public CraftInventoryView getBukkitView(EntityHuman player, InventoryHolder holder) { + try { + AnvilInventoryCustom craftInventory = new AnvilInventoryCustom(holder, + new Location(entity.world.getWorld(), 0, 0, 0), + (IInventory) mc_ContainerAnvil_repairInventory.get(this), + (IInventory) mc_ContainerAnvil_resultInventory.get(this), this); + CraftInventoryView view = new CraftInventoryView(player.getBukkitEntity(), craftInventory, this); + mc_ContainerAnvil_bukkitEntity.set(this, view); + return view; + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Setup Error", ex); + } + return getBukkitView(); + } + + @Override + public boolean canUse(EntityHuman entityhuman) { + return canUse; + } + + @Override + public void e() { + super.e(); + if (cost >= 0) { + if (compat_mode) { + if (mc_ContainerProperty_set != null) { + try { + mc_ContainerProperty_set.invoke(this.levelCost, 0); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + mc_ContainerProperty_set = null; + } + } + } else { + this.levelCost.set(cost); + } + } + textChange.onChange(); + } + + @Override + public void update() { + e(); + } + + @Override + public String getRenameText() { + return this.renameText; + } + + @Override + public void setRenameText(String text) { + this.a(text); + } + + @Override + public void setOnChange(AnvilTextChange handler) { + textChange = handler; + } + + @Override + public String getCustomTitle() { + return customTitle; + } + + @Override + public void setCustomTitle(String title) { + this.customTitle = title; + try { + mc_Container_title.set(this, new ChatMessage(customTitle != null ? customTitle : "")); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + } + } + + @Override + public void setLevelCost(int cost) { + this.cost = cost; + } + + @Override + public int getLevelCost() { + if (cost >= 0) { + return cost; + } else if (compat_mode) { + if (mc_ContainerProperty_get != null) { + try { + return (int) mc_ContainerProperty_get.invoke(this.levelCost); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Error", ex); + mc_ContainerProperty_get = null; + } + } + } else { + return this.levelCost.get(); + } + return -1; + } + + @Override + public void setCanUse(boolean bool) { + this.canUse = bool; + } + + @Override + public ItemStack getLeftInput() { + return inventory.getItem(0); + } + + @Override + public ItemStack getRightInput() { + return inventory.getItem(1); + } + + @Override + public ItemStack getOutput() { + return inventory.getItem(2); + } + + @Override + public void setLeftInput(ItemStack item) { + inventory.setItem(0, item); + } + + @Override + public void setRightInput(ItemStack item) { + inventory.setItem(1, item); + } + + @Override + public void setOutput(ItemStack item) { + inventory.setItem(2, item); + } + + @Override + public Inventory getInventory() { + return inventory; + } + + @Override + public void open() { + + // Counter stuff that the game uses to keep track of inventories + int id = entity.nextContainerCounter(); + + // Send the packet + entity.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, Containers.ANVIL, new ChatMessage(customTitle != null ? customTitle : ""))); + + // Set their active container to this anvil + entity.activeContainer = this; + + try { + // Set their active container window id to that counter stuff + mc_Container_windowId.set(this, id); + } catch (Exception ex) { + Logger.getLogger(AnvilView.class.getName()).log(Level.SEVERE, "Anvil Create Error", ex); + } + + // Add the slot listener + entity.activeContainer.addSlotListener(entity); + } + +} diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/NMS.java b/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/NMS.java new file mode 100644 index 00000000..2e546a99 --- /dev/null +++ b/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/NMS.java @@ -0,0 +1,24 @@ +package com.songoda.core.nms.v1_15_R1; + +import com.songoda.core.nms.CoreNMS; +import com.songoda.core.nms.CustomAnvil; +import net.minecraft.server.v1_15_R1.EntityPlayer; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryHolder; + +public class NMS implements CoreNMS { + + @Override + public CustomAnvil createAnvil(Player player) { + EntityPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, null); + } + + @Override + public CustomAnvil createAnvil(Player player, InventoryHolder holder) { + EntityPlayer p = ((CraftPlayer) player).getHandle(); + return new AnvilView(p.nextContainerCounter(), p, holder); + } + +} diff --git a/pom.xml b/pom.xml index 96a9a46f..3320e10a 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ NMS/NMS-v1_13_R1 NMS/NMS-v1_13_R2 NMS/NMS-v1_14_R1 + NMS/NMS-v1_15_R1 From 288eae8f47b07630c9a75c142e35ce5e24916334 Mon Sep 17 00:00:00 2001 From: Brianna Date: Wed, 11 Dec 2019 14:15:10 -0500 Subject: [PATCH 19/27] version 2.3 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 729b0b66..8e3c469b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.2.12" + version: "2.3" build: stage: build From 2ea41e962dda2bdb2e8b3bb69a2244af68cb0023 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 28 Dec 2019 15:21:43 -0500 Subject: [PATCH 20/27] Added Economy option. --- .../java/com/songoda/core/hooks/EconomyManager.java | 13 +++++++++++++ .../com/songoda/core/hooks/economies/Economy.java | 8 ++++++++ .../core/hooks/economies/PlayerPointsEconomy.java | 5 +++++ .../core/hooks/economies/ReserveEconomy.java | 5 +++++ .../songoda/core/hooks/economies/VaultEconomy.java | 9 ++++++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java b/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java index e2a6dc0f..a09c00af 100644 --- a/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java +++ b/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java @@ -61,6 +61,19 @@ public class EconomyManager { return manager.isEnabled() ? manager.getCurrentHook().formatEconomy(amt) : String.valueOf(amt); } + /** + * Get the players available balance + * + * @param player player + * @return the amount of available balance + */ + public static double getBalance(OfflinePlayer player) { + if (!manager.isEnabled()) + return 0; + return manager.getCurrentHook().getBalance(player); + + } + /** * Check to see if a player has at least some balance available.
* NOTE: using a default economy assumes that this library is shaded diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java b/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java index 7c304f7e..54d7e03d 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java @@ -6,6 +6,14 @@ import org.bukkit.OfflinePlayer; public abstract class Economy implements Hook { + /** + * Get the players available balance + * + * @param player player + * @return the amount of available balance + */ + public abstract double getBalance(OfflinePlayer player); + /** * Check to see if a player has at least some balance available * diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java b/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java index 8856ebb2..98dbf3c2 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java @@ -26,6 +26,11 @@ public class PlayerPointsEconomy extends Economy { return "PlayerPoints"; } + @Override + public double getBalance(OfflinePlayer player) { + return playerPoints.getAPI().look(player.getUniqueId()); + } + @Override public boolean hasBalance(OfflinePlayer player, double cost) { int amount = convertAmount(cost); diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java b/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java index 93a9788d..a2483dea 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/ReserveEconomy.java @@ -30,6 +30,11 @@ public class ReserveEconomy extends Economy { return economyAPI.format(BigDecimal.valueOf(amt)); } + @Override + public double getBalance(OfflinePlayer player) { + return economyAPI.getBankHoldings(player.getUniqueId()).doubleValue(); + } + @Override public boolean hasBalance(OfflinePlayer player, double cost) { return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost)); diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java b/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java index 2726a2ec..684619c5 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/VaultEconomy.java @@ -9,7 +9,7 @@ public class VaultEconomy extends Economy { private final net.milkbowl.vault.economy.Economy vault; public VaultEconomy() { - // this returns null if we have Vault with no compatibe eco plugin + // this returns null if we have Vault with no compatible eco plugin RegisteredServiceProvider v = Bukkit.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); if(v != null) { this.vault = v.getProvider(); @@ -34,6 +34,13 @@ public class VaultEconomy extends Economy { return vault != null ? vault.format(amt) : super.formatEconomy(amt); } + @Override + public double getBalance(OfflinePlayer player) { + if (vault == null) + return 0; + return vault.getBalance(player); + } + @Override public boolean hasBalance(OfflinePlayer player, double cost) { return vault != null && vault.has(player, cost); From 30e38b5969dbafdf939314c17c974989fe6f4489 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 28 Dec 2019 15:21:49 -0500 Subject: [PATCH 21/27] version 2.3.1 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8e3c469b..f07adfe5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.3" + version: "2.3.1" build: stage: build From 906f13405fa92c05d68fb20c9e6cfab52c5df5e2 Mon Sep 17 00:00:00 2001 From: Steven Conley Date: Wed, 15 Jan 2020 20:47:11 -0600 Subject: [PATCH 22/27] Added a check for UltimateCatcher. --- .../com/songoda/core/compatibility/CompatibleMaterial.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index 7abfff2f..b5bc7394 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -2166,6 +2166,11 @@ public enum CompatibleMaterial { if(type == EntityType.MUSHROOM_COW) { return MOOSHROOM_SPAWN_EGG; } + + if (type == EntityType.PIG_ZOMBIE) { + return ZOMBIE_PIGMAN_SPAWN_EGG; + } + return lookupMap.get(type.name() + "_SPAWN_EGG"); } From a84bd5ddc2a2bfca65bb347f62abfc7bd63f7567 Mon Sep 17 00:00:00 2001 From: Brianna Date: Wed, 15 Jan 2020 22:18:40 -0500 Subject: [PATCH 23/27] version 2.3.2 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f07adfe5..67087619 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.3.1" + version: "2.3.2" build: stage: build From 27dbc0ff484e27125a3537916b4226ebf6c22891 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 19 Jan 2020 17:59:43 -0500 Subject: [PATCH 24/27] Fix nether warts --- .../com/songoda/core/utils/BlockUtils.java | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/utils/BlockUtils.java b/Core/src/main/java/com/songoda/core/utils/BlockUtils.java index 52a406ea..4199b44e 100644 --- a/Core/src/main/java/com/songoda/core/utils/BlockUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/BlockUtils.java @@ -1,22 +1,19 @@ package com.songoda.core.utils; import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.compatibility.ServerVersion; +import org.bukkit.Bukkit; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.EnumSet; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import org.bukkit.Bukkit; -import org.bukkit.CropState; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; -import org.bukkit.material.Crops; public class BlockUtils { @@ -69,10 +66,10 @@ public class BlockUtils { if (isOpenable(bType)) { toggleDoorStates(true, b); return true; - } else if(bType == Material.LEVER) { + } else if (bType == Material.LEVER) { toggleLever(b); return true; - } else if(bType.name().endsWith("_BUTTON")) { + } else if (bType.name().endsWith("_BUTTON")) { pressButton(b); return true; } @@ -82,6 +79,7 @@ public class BlockUtils { /** * Change a pressure plate's redstone state + * * @param plate plate to update * @param power power to set to 0-15 (wood plates are active if greater than 0) */ @@ -105,7 +103,7 @@ public class BlockUtils { Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); } } - + public static void pressButton(Block button) { if (useLegacy && legacySetBlockData != null) { _pressButtonLegacy(button); @@ -113,7 +111,7 @@ public class BlockUtils { BlockUtilsModern._pressButtonModern(button); } } - + public static void releaseButton(Block button) { if (useLegacy && legacySetBlockData != null) { _releaseButtonLegacy(button); @@ -124,7 +122,7 @@ public class BlockUtils { private static void _pressButtonLegacy(Block button) { final Material m = button.getType(); - if(!m.name().endsWith("_BUTTON")) return; + if (!m.name().endsWith("_BUTTON")) return; try { legacySetBlockData.invoke(button, (byte) (button.getData() | (31 & 0x8))); button.getState().update(); @@ -132,10 +130,10 @@ public class BlockUtils { Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); } } - + private static void _releaseButtonLegacy(Block button) { final Material m = button.getType(); - if(!m.name().endsWith("_BUTTON")) return; + if (!m.name().endsWith("_BUTTON")) return; try { legacySetBlockData.invoke(button, (byte) (button.getData() & ~0x8)); button.getState().update(); @@ -143,7 +141,7 @@ public class BlockUtils { Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); } } - + public static void toggleLever(Block lever) { if (useLegacy && legacySetBlockData != null) { _toggleLeverLegacy(lever); @@ -154,7 +152,7 @@ public class BlockUtils { private static void _toggleLeverLegacy(Block lever) { final Material m = lever.getType(); - if(m != Material.LEVER) return; + if (m != Material.LEVER) return; try { legacySetBlockData.invoke(lever, (byte) (lever.getData() ^ 0x8)); lever.getState().update(); @@ -189,6 +187,7 @@ public class BlockUtils { Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); } } + /** * Change all of the given door states to be inverse; that is, if a door is * open, it will be closed afterwards. If the door is closed, it will become @@ -197,8 +196,8 @@ public class BlockUtils { * Note that the blocks given must be the bottom block of the door. * * @param allowDoorToOpen If FALSE, and the door is currently CLOSED, it - * will NOT be opened! - * @param doors Blocks given must be the bottom block of the door + * will NOT be opened! + * @param doors Blocks given must be the bottom block of the door */ public static void toggleDoorStates(boolean allowDoorToOpen, Block... doors) { if (useLegacy && legacySetBlockData != null) { @@ -312,6 +311,7 @@ public class BlockUtils { /** * Manually trigger the updateAdjacentComparators method for containers + * * @param containerLocation location of the container */ public static void updateAdjacentComparators(Location containerLocation) { @@ -363,7 +363,8 @@ public class BlockUtils { if (mat == null || !mat.isCrop()) { return false; } else { - return block.getData() >= (mat == CompatibleMaterial.BEETROOTS ? 3 : 7); + return block.getData() >= (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); } } @@ -383,7 +384,8 @@ public class BlockUtils { if (mat == null || !mat.isCrop()) { return -1; } else { - return mat == CompatibleMaterial.BEETROOTS ? 3 : 7; + return (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); } } @@ -403,7 +405,8 @@ public class BlockUtils { if (mat == null || !mat.isCrop()) { return -1; } else { - return mat == CompatibleMaterial.BEETROOTS ? 3 : 7; + return (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); } } @@ -421,7 +424,8 @@ public class BlockUtils { CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); if (mat != null && mat.isCrop()) { try { - legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, mat == CompatibleMaterial.BEETROOTS ? 3 : 7))); + legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)))); } catch (Exception ex) { Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); } @@ -440,7 +444,8 @@ public class BlockUtils { BlockUtilsModern._incrementGrowthStage(block); } else { CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); - if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS ? 3 : 7)) { + if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)) { try { legacySetBlockData.invoke(block, (byte) (block.getData() + 1)); } catch (Exception ex) { @@ -473,7 +478,7 @@ public class BlockUtils { /** * Check to see if this material does not impede player/mob movement at all. - * + * * @param m material to check * @return true if this material doesn't have a solid hitbox */ @@ -625,7 +630,7 @@ public class BlockUtils { case "WITHER_ROSE": case "YELLOW_BANNER": case "YELLOW_WALL_BANNER": - // Legacy values: + // Legacy values: case "WEB": case "LONG_GRASS": case "YELLOW_FLOWER": @@ -658,7 +663,7 @@ public class BlockUtils { /** * Check to see if a player can walk into this material
* This includes blocks like slabs and stairs - * + * * @param m material to check * @return true if this is a block that can be walked though or up */ @@ -936,7 +941,7 @@ public class BlockUtils { case "YELLOW_BANNER": case "YELLOW_CARPET": case "YELLOW_WALL_BANNER": - // Legacy values: + // Legacy values: case "WEB": case "LONG_GRASS": case "YELLOW_FLOWER": From 408cf3ee5e5d829658b120c06e3c0f0544195b4b Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 19 Jan 2020 17:59:58 -0500 Subject: [PATCH 25/27] 2.3.3 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 67087619..3112766d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.3.2" + version: "2.3.3" build: stage: build From 309a502caa232920c8e8aa836ae5066c40cfbd69 Mon Sep 17 00:00:00 2001 From: Brianna Date: Tue, 21 Jan 2020 10:27:34 -0500 Subject: [PATCH 26/27] particle fix --- .../core/compatibility/CompatibleParticleHandler.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java b/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java index 708a171d..ceb58048 100644 --- a/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java +++ b/Core/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java @@ -13,12 +13,6 @@ import java.util.stream.Stream; public class CompatibleParticleHandler { public static enum ParticleType { - /* 1.15 */ - DRIPPING_HONEY, - FALLING_HONEY, - FALLING_NECTAR, - LANDING_HONEY, - EXPLOSION_NORMAL(), EXPLOSION_LARGE, EXPLOSION_HUGE, @@ -87,6 +81,11 @@ public class CompatibleParticleHandler { LANDING_LAVA(ServerVersion.V1_14, "LAVA"), FALLING_WATER(ServerVersion.V1_14, "DRIP_WATER"), /// End 1.14 /// + DRIPPING_HONEY(ServerVersion.V1_15, "DRIP_WATER"), + FALLING_HONEY(ServerVersion.V1_15, "DRIP_WATER"), + FALLING_NECTAR(ServerVersion.V1_15, "DRIP_WATER"), + LANDING_HONEY(ServerVersion.V1_15, "DRIP_WATER"), + /// End 1.15 /// ; final boolean compatibilityMode; From 76c7e7a0f93e65d7d05e408b211a9f998c8e0b25 Mon Sep 17 00:00:00 2001 From: Brianna Date: Tue, 21 Jan 2020 10:28:16 -0500 Subject: [PATCH 27/27] version 2.3.4 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3112766d..5a050c5b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "SongodaCore" path: "/builds/$CI_PROJECT_PATH" - version: "2.3.3" + version: "2.3.4" build: stage: build