Add basic MC 1.13 support

TODO:
- Title switching between owner and other viewers
- Upgrading from older MC versions
This commit is contained in:
GeorgH93 2018-07-22 22:57:32 +02:00
parent 001f35bf77
commit 5a60f09ed7
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
8 changed files with 51 additions and 36 deletions

10
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.17.9</version>
<version>1.17.11</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>
@ -52,13 +52,13 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<version>1.13-pre7-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>PluginLib</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
@ -114,7 +114,7 @@
</includes>
</artifactSet>
<relocations>
<relocation>
<!--<relocation>
<pattern>at.pcgamingfreaks</pattern>
<shadedPattern>at.pcgamingfreaks.MinePacks.libs.at.pcgamingfreaks</shadedPattern>
<excludes>
@ -122,7 +122,7 @@
<exclude>at.pcgamingfreaks.MinePacks.Database.*</exclude>
<exclude>at.pcgamingfreaks.MinePacks.Updater.*</exclude>
</excludes>
</relocation>
</relocation>-->
<relocation>
<pattern>com.zaxxer.hikari</pattern>
<shadedPattern>at.pcgamingfreaks.MinePacks.libs.zaxxer.hikari</shadedPattern>

View File

@ -24,6 +24,7 @@ permissions:
backpack.fullpickup: true
backpack.disable:
description: This permission group can be used to disable the plugin for certian users/groups/worlds.
default: false
children:
backpack: false
backpack.use: false

View File

@ -17,6 +17,7 @@
package at.pcgamingfreaks.MinePacks;
import at.pcgamingfreaks.Bukkit.MCVersion;
import at.pcgamingfreaks.Bukkit.NMSReflection;
import at.pcgamingfreaks.StringUtils;
@ -119,8 +120,15 @@ public void open(Player p, boolean editable)
{
//noinspection ConstantConditions
FIELD_TITLE.setAccessible(true);
//noinspection ConstantConditions
FIELD_TITLE.set(METHOD_GET_INVENTORY.invoke(bp), p.equals(owner) ? MinePacks.backpackTitle : titleOther);
if(MCVersion.isOlderThan(MCVersion.MC_NMS_1_13_R1))
{
//noinspection ConstantConditions
FIELD_TITLE.set(METHOD_GET_INVENTORY.invoke(bp), p.equals(owner) ? MinePacks.backpackTitle : titleOther);
}
else
{
//TODO convert title to IChatBaseComponent
}
}
catch(Exception e)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2017 GeorgH93
* Copyright (C) 2014-2018 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -18,6 +18,7 @@
package at.pcgamingfreaks.MinePacks.Database;
import at.pcgamingfreaks.Bukkit.Configuration;
import at.pcgamingfreaks.YamlFileManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -40,28 +41,28 @@ protected void doUpdate()
{
// Nothing to update yet
}
@Override
protected void doUpgrade(at.pcgamingfreaks.Configuration oldConfig)
protected void doUpgrade(YamlFileManager oldConfig)
{
Set<String> keys = oldConfig.getConfig().getKeys();
Set<String> keys = oldConfig.getYaml().getKeys();
for(String key : keys)
{
if(key.equals("UseUUIDs") || key.equals("Version") || (key.equals("BackpackTitle") && oldConfig.getVersion() < 11)) continue;
try
{
getConfig().set(key, oldConfig.getConfig().getString(key));
getConfig().set(key, oldConfig.getYaml().getString(key));
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(!oldConfig.getConfig().isSet("Database.UseUUIDs"))
if(!oldConfig.getYaml().isSet("Database.UseUUIDs"))
{
if(oldConfig.getConfig().isSet("UseUUIDs"))
if(oldConfig.getYaml().isSet("UseUUIDs"))
{
getConfig().set("Database.UseUUIDs", oldConfig.getConfig().getBoolean("UseUUIDs", true));
getConfig().set("Database.UseUUIDs", oldConfig.getYaml().getBoolean("UseUUIDs", true));
}
else
{
@ -70,7 +71,7 @@ protected void doUpgrade(at.pcgamingfreaks.Configuration oldConfig)
}
if(oldConfig.getVersion() < 11)
{
getConfig().set("BackpackTitleOther", oldConfig.getConfig().getString("BackpackTitle", "&b{OwnerName} Backpack").replaceAll("%s", "{OwnerName}"));
getConfig().set("BackpackTitleOther", oldConfig.getYaml().getString("BackpackTitle", "&b{OwnerName} Backpack").replaceAll("%s", "{OwnerName}"));
}
}
@ -154,7 +155,7 @@ public boolean getUseUUIDSeparators()
public String getBPTitleOther()
{
return ChatColor.translateAlternateColorCodes('&', getConfig().getString("BackpackTitleOther", "{OwnerName} Backpack").replaceAll("%", "%%").replaceAll("\\{OwnerName\\}", "%s"));
return ChatColor.translateAlternateColorCodes('&', getConfig().getString("BackpackTitleOther", "{OwnerName} Backpack").replaceAll("%", "%%").replaceAll("\\{OwnerName}", "%s"));
}
public String getBPTitle()

View File

@ -28,17 +28,17 @@
public class Database
{
protected MinePacks plugin;
protected final MinePacks plugin;
protected final InventorySerializer itsSerializer;
private final HashMap<OfflinePlayer, Backpack> backpacks = new HashMap<>();
protected boolean useUUIDs, useUUIDSeparators, bungeeMode;
protected long maxAge;
private HashMap<OfflinePlayer, Backpack> backpacks = new HashMap<>();
protected InventorySerializer itsSerializer = new InventorySerializer();
public Database(MinePacks mp)
{
plugin = mp;
itsSerializer = new InventorySerializer(plugin.getLogger());
useUUIDSeparators = plugin.config.getUseUUIDSeparators();
useUUIDs = plugin.config.getUseUUIDs();
maxAge = plugin.config.getAutoCleanupMaxInactiveDays();

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2017 GeorgH93
* Copyright (C) 2014-2018 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,18 +21,23 @@
import at.pcgamingfreaks.Bukkit.ItemStackSerializer.ItemStackSerializer;
import at.pcgamingfreaks.Bukkit.ItemStackSerializer.NBTItemStackSerializer;
import at.pcgamingfreaks.Bukkit.MCVersion;
import at.pcgamingfreaks.ConsoleColor;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.logging.Logger;
public class InventorySerializer
{
ItemStackSerializer serializer, baseItemStackSerializer = new BukkitItemStackSerializer();
int usedSerializer = 1;
private ItemStackSerializer serializer, baseItemStackSerializer = new BukkitItemStackSerializer();
private int usedSerializer = 1;
private Logger logger;
public InventorySerializer()
public InventorySerializer(Logger logger)
{
this.logger = logger;
try
{
if(MCVersion.isNewerOrEqualThan(MCVersion.MC_1_7) && MCVersion.isOlderOrEqualThan(MCVersion.MC_1_7_10) &&
@ -61,17 +66,17 @@ public byte[] serialize(Inventory inv)
return serializer.serialize(inv.getContents());
}
@SuppressWarnings("unused")
public ItemStack[] deserialize(byte[] data)
{
return deserialize(data, usedSerializer);
}
public ItemStack[] deserialize(byte[] data, int usedSerializer)
{
switch(usedSerializer)
{
case 0: return baseItemStackSerializer.deserialize(data);
case 1:
if(usedSerializer != this.usedSerializer)
{
logger.warning(ConsoleColor.RED + "No compatible serializer for item format available!" + ConsoleColor.RESET);
return null;
}
default: return serializer.deserialize(data);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 GeorgH93
* Copyright (C) 2014-2018 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,10 +34,10 @@ protected void doUpdate()
{
switch(getVersion())
{
case 1: lang.set("Language.Ingame.Cooldown", "Please wait till you reopen your backpack.");
case 2: lang.set("Language.Ingame.InvalidBackpack", lang.getString("Language.Ingame.IvalidBackpack", "Invalid backpack."));
case 1: yaml.set("Language.Ingame.Cooldown", "Please wait till you reopen your backpack.");
case 2: yaml.set("Language.Ingame.InvalidBackpack", yaml.getString("Language.Ingame.IvalidBackpack", "Invalid backpack."));
case 3:
case 4: lang.set("Language.Ingame.WrongGameMode", "You are not allowed to open your backpack in your current game-mode.");
case 4: yaml.set("Language.Ingame.WrongGameMode", "You are not allowed to open your backpack in your current game-mode.");
break;
}
}

View File

@ -69,7 +69,7 @@ public void onEnable()
//region Check compatibility with used minecraft version
String name = Bukkit.getServer().getClass().getPackage().getName();
String[] version = name.substring(name.lastIndexOf('.') + 2).split("_");
if((version[0].equals("1") && Integer.valueOf(version[1]) > 12) || Integer.valueOf(version[0]) > 1)
if((version[0].equals("1") && Integer.valueOf(version[1]) > 13) || Integer.valueOf(version[0]) > 1)
{
MinePacks.getInstance().warnOnVersionIncompatibility(version[0] + "." + version[1]);
this.setEnabled(false);