Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
1.14 update stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatsmusic99 committed Apr 24, 2019
1 parent 61db74c commit b10a716
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 45 deletions.
64 changes: 62 additions & 2 deletions main/java/io/github/thatsmusic99/headsplus/HeadsPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.github.thatsmusic99.headsplus.nms.v1_12_NMS.v1_12_NMS;
import io.github.thatsmusic99.headsplus.nms.v1_13_NMS.v1_13_NMS;
import io.github.thatsmusic99.headsplus.nms.v1_13_R2_NMS.v1_13_R2_NMS;
import io.github.thatsmusic99.headsplus.nms.v1_14_R1_NMS.v1_14_R1_NMS;
import io.github.thatsmusic99.headsplus.nms.v1_8_R1_NMS.v1_8_R1_NMS;
import io.github.thatsmusic99.headsplus.nms.v1_8_R2_NMS.v1_8_R2_NMS;
import io.github.thatsmusic99.headsplus.nms.v1_8_R3_NMS.v1_8_R3NMS;
Expand All @@ -36,7 +37,6 @@
import io.github.thatsmusic99.specprotect.CoreClass;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -154,7 +154,7 @@ public void onEnable() {
debug("- Creating Metrics!", 1);
Metrics metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SimplePie("languages", () -> LocaleManager.getLocale().getLanguage()));
metrics.addCustomChart(new Metrics.SimplePie("theme", () -> WordUtils.capitalize(getConfiguration().getMechanics().getString("plugin-theme-dont-change").toLowerCase())));
metrics.addCustomChart(new Metrics.SimplePie("theme", () -> capitalize(getConfiguration().getMechanics().getString("plugin-theme-dont-change").toLowerCase())));
debug("- Metrics complete, can be found at https://bstats.org/plugin/bukkit/HeadsPlus", 2);
if (getConfiguration().getMechanics().getBoolean("update.check")) {
new BukkitRunnable() {
Expand Down Expand Up @@ -195,6 +195,10 @@ public void run() {
} catch (Exception ex) {
getLogger().severe("HeadsPlus has failed to start up correctly and can not read the config. An error report has been made in /plugins/HeadsPlus/debug");
try {
getLogger().info("First stacktrace: ");
e.printStackTrace();
getLogger().info("Second stacktrace: ");
ex.printStackTrace();
String s = new DebugFileCreator().createReport(e, "Startup");
getLogger().severe("Report name: " + s);
getLogger().severe("Please submit this report to the developer at one of the following links:");
Expand Down Expand Up @@ -471,13 +475,23 @@ private void setupNMS() {
managers.add(new v1_12_NMS());
managers.add(new v1_13_NMS());
managers.add(new v1_13_R2_NMS());
managers.add(new v1_14_R1_NMS());
String a = getServer().getClass().getPackage().getName();
String version = a.substring(a.lastIndexOf('.') + 1);
for (NMSManager nms : managers) {
if (nms.getNMSVersion().equalsIgnoreCase(version)) {
this.nms = nms;
}
}
if (nms instanceof v1_14_R1_NMS) {
String supportedHash = "8b7fe9012a93b36df04844a6c990de27";
getLogger().info("1.14 detected! NMS mapping version: " + ((org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers) getServer().getUnsafe()).getMappingsVersion());
if (supportedHash.equalsIgnoreCase(((org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers) getServer().getUnsafe()).getMappingsVersion())) {
getLogger().info("Current hash is supported.");
} else {
getLogger().info("Current hash is not supported. If any issues arise, let the developer know!");
}
}
if (this.nms == null) {
getLogger().severe("ERROR: HeadsPlus does not support this version (" + version + ")!");
getLogger().severe("If this is not known of, let the developer know in one of these places:");
Expand Down Expand Up @@ -723,4 +737,50 @@ public void checkForMutuals() {
public void reloadDE() {
de.reload();
}

public static String capitalize(String str) {
return capitalize(str, null);
}

public static String capitalize(String str, char[] delimiters) {
int delimLen = delimiters == null ? -1 : delimiters.length;
if (str != null && str.length() != 0 && delimLen != 0) {
int strLen = str.length();
StringBuffer buffer = new StringBuffer(strLen);
boolean capitalizeNext = true;

for(int i = 0; i < strLen; ++i) {
char ch = str.charAt(i);
if (isDelimiter(ch, delimiters)) {
buffer.append(ch);
capitalizeNext = true;
} else if (capitalizeNext) {
buffer.append(Character.toTitleCase(ch));
capitalizeNext = false;
} else {
buffer.append(ch);
}
}

return buffer.toString();
} else {
return str;
}
}

private static boolean isDelimiter(char ch, char[] delimiters) {
if (delimiters == null) {
return Character.isWhitespace(ch);
} else {
int i = 0;

for(int isize = delimiters.length; i < isize; ++i) {
if (ch == delimiters[i]) {
return true;
}
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.github.thatsmusic99.headsplus.locale.LocaleManager;
import io.github.thatsmusic99.headsplus.util.MaterialTranslator;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -158,7 +157,7 @@ public void complete(Player p, Inventory i, int slot) {
.append(ChatColor.GREEN)
.append(getRewardItemAmount())
.append(" ")
.append(WordUtils.capitalize(getRewardValue().toString().replaceAll("_", " ")));
.append(HeadsPlus.capitalize(getRewardValue().toString().replaceAll("_", " ")));
sb2
.append(getRewardItemAmount())
.append(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void addMHFHeads() {
&& !key.equals("sheep")
&& !key.equals("llama")
&& !key.equals("parrot")) {
getConfig().addDefault(key + ".name", new ArrayList<>(Collections.singleton("MHF_" + WordUtils.capitalize(key))));
getConfig().addDefault(key + ".name", new ArrayList<>(Collections.singleton("MHF_" + HeadsPlus.capitalize(key))));

} else if (key.equals("irongolem")) {
getConfig().addDefault(key + ".name", new ArrayList<>(Collections.singleton("MHF_Golem")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onClick(Player p, InventoryManager im, InventoryClickEvent e) {
p.closeInventory();
final InventoryClickEvent ev = e;
try {
if (HeadsPlus.getInstance().getConfiguration().getMechanics().getBoolean("anvil-menu-search")) {
/* if (HeadsPlus.getInstance().getConfiguration().getMechanics().getBoolean("anvil-menu-search")) {
SearchGUI s = HeadsPlus.getInstance().getNMS().getSearchGUI(p, event -> {
if (event.getSlot().equals(SearchGUI.AnvilSlot.OUTPUT)) {
Expand All @@ -47,7 +47,7 @@ public void onClick(Player p, InventoryManager im, InventoryClickEvent e) {
});
s.setSlot(SearchGUI1_12.AnvilSlot.INPUT_LEFT, new ItemStack(Material.NAME_TAG));
s.open();
} else {
} else { */
ConversationFactory c = new ConversationFactory(HeadsPlus.getInstance());
Conversation conv = c.withFirstPrompt(new ChatPrompt()).withLocalEcho(false).buildConversation(p);
conv.addConversationAbandonedListener(event -> {
Expand All @@ -64,7 +64,7 @@ public void onClick(Player p, InventoryManager im, InventoryClickEvent e) {

});
conv.begin();
}
// }

} catch (Exception ex) {
new DebugPrint(ex, "Event (InventoryEvent)", false, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
package io.github.thatsmusic99.headsplus.nms.v1_14_R1_NMS;

public class SearchGUI1_14_R1 {
import io.github.thatsmusic99.headsplus.nms.SearchGUI;
import net.minecraft.server.v1_14_R1.*;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;

public class SearchGUI1_14_R1 extends SearchGUI {
public SearchGUI1_14_R1(Player player, AnvilClickEventHandler handler) {
super(player, handler);
}

private class AnvilContainer extends ContainerAnvil {
public AnvilContainer(EntityHuman entity) {
super(((CraftPlayer)((Player) entity)).getHandle().nextContainerCounter(), entity.inventory);
}

@Override
public boolean canUse(EntityHuman entityhuman) {
return true;
}
}


public void open() {
EntityPlayer p = ((CraftPlayer) getPlayer()).getHandle();

AnvilContainer container = new AnvilContainer(p);

//Set the items to the items from the inventory given
inv = container.getBukkitView().getTopInventory();

for (AnvilSlot slot : items.keySet()) {
inv.setItem(slot.getSlot(), items.get(slot));
}

//Counter stuff that the game uses to keep track of inventories
int c = p.nextContainerCounter();

//Send the packet
// p.playerConnection.sendPacket(new PacketPlayOutOpenWindow(0, container, new ChatMessage("Repairing")));
//Set their active container to the container
p.activeContainer = container;

//Set their active container window id to that counter stuff

//Add the slot listener
p.activeContainer.addSlotListener(p);
}
}
Loading

0 comments on commit b10a716

Please sign in to comment.