mirror of
https://e.coding.net/circlecloud/RealBackpacks.git
synced 2024-12-04 03:49:07 +00:00
fix Chinese can't use in MySQL...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
parent
78a14cd70c
commit
11a8b85427
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cn.CityCraft</groupId>
|
<groupId>cn.CityCraft</groupId>
|
||||||
<artifactId>RealBackpacks</artifactId>
|
<artifactId>RealBackpacks</artifactId>
|
||||||
<version>0.1.2-SNAPSHOT</version>
|
<version>0.1.3-SNAPSHOT</version>
|
||||||
<name>RealBackpacks</name>
|
<name>RealBackpacks</name>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
@ -122,9 +122,11 @@ public class RealBackpacks extends JavaPlugin {
|
|||||||
new InventoryListener(this), this);
|
new InventoryListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(
|
getServer().getPluginManager().registerEvents(
|
||||||
new EntityListener(this), this);
|
new EntityListener(this), this);
|
||||||
getCommand("rb").setExecutor(new MainCommand(this));
|
|
||||||
getServer().getScheduler().runTaskTimer(this,
|
getServer().getScheduler().runTaskTimer(this,
|
||||||
new WalkSpeedRunnable(this), 20, 20);
|
new WalkSpeedRunnable(this), 20, 20);
|
||||||
|
|
||||||
|
getCommand("rb").setExecutor(new MainCommand(this));
|
||||||
|
|
||||||
getLogger().info("真实背包已加载 By: 喵♂呜.");
|
getLogger().info("真实背包已加载 By: 喵♂呜.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import cn.citycraft.plugins.RealBackpacks;
|
import cn.citycraft.plugins.RealBackpacks;
|
||||||
import cn.citycraft.plugins.util.MysqlFunctions;
|
import cn.citycraft.plugins.util.MysqlFunctions;
|
||||||
@ -193,8 +194,8 @@ public class InventoryListener implements Listener {
|
|||||||
if (potentialBackpack != null
|
if (potentialBackpack != null
|
||||||
&& plugin.backpackItems
|
&& plugin.backpackItems
|
||||||
.containsKey(potentialBackpack)) {
|
.containsKey(potentialBackpack)) {
|
||||||
if (curItem.isSimilar(plugin.backpackItems
|
if (isSimilar(curItem,
|
||||||
.get(potentialBackpack))) {
|
plugin.backpackItems.get(potentialBackpack))) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
|
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
|
||||||
return;
|
return;
|
||||||
@ -235,4 +236,44 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public boolean isSimilar(ItemStack origin, ItemStack compare) {
|
||||||
|
if (compare == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (compare == origin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return compare.getTypeId() == origin.getTypeId()
|
||||||
|
&& compare.getDurability() == origin.getDurability()
|
||||||
|
&& compare.hasItemMeta() == origin.hasItemMeta()
|
||||||
|
&& (compare.hasItemMeta() ? isSimilarMeta(
|
||||||
|
compare.getItemMeta(), origin.getItemMeta()) : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSimilarMeta(ItemMeta origin, ItemMeta compare) {
|
||||||
|
if (origin.hasDisplayName() != compare.hasDisplayName())
|
||||||
|
return false;
|
||||||
|
if (origin.hasEnchants() != compare.hasEnchants())
|
||||||
|
return false;
|
||||||
|
if (origin.hasLore() != compare.hasLore())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (origin.hasDisplayName() && compare.hasDisplayName()) {
|
||||||
|
if (!origin.getDisplayName().equals(compare.getDisplayName()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (origin.hasEnchants() && compare.hasEnchants()) {
|
||||||
|
if (!origin.getEnchants().equals(compare.getEnchants()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (origin.hasLore() && compare.hasLore()) {
|
||||||
|
if (!(origin.getLore().containsAll(compare.getLore()) || compare
|
||||||
|
.getLore().containsAll(origin.getLore())))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,10 @@ public class MysqlFunctions {
|
|||||||
|
|
||||||
public static boolean checkIfTableExists(final String table) {
|
public static boolean checkIfTableExists(final String table) {
|
||||||
try {
|
try {
|
||||||
final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
//final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
||||||
|
String url = plugin.getUrl()+"?"
|
||||||
|
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
||||||
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
final Statement state = conn.createStatement();
|
final Statement state = conn.createStatement();
|
||||||
final DatabaseMetaData dbm = conn.getMetaData();
|
final DatabaseMetaData dbm = conn.getMetaData();
|
||||||
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
|
final ResultSet tables = dbm.getTables(null, null, "rb_data", null);
|
||||||
@ -43,8 +46,10 @@ public class MysqlFunctions {
|
|||||||
|
|
||||||
public static void createTables() {
|
public static void createTables() {
|
||||||
try {
|
try {
|
||||||
final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
String url = plugin.getUrl()+"?"
|
||||||
final PreparedStatement state = conn.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT);");
|
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
||||||
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
|
final PreparedStatement state = conn.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
|
||||||
state.executeUpdate();
|
state.executeUpdate();
|
||||||
state.close();
|
state.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
@ -58,7 +63,9 @@ public class MysqlFunctions {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
String url = plugin.getUrl()+"?"
|
||||||
|
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
||||||
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
PreparedStatement statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
|
PreparedStatement statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
|
||||||
statement.setString(1, playerName);
|
statement.setString(1, playerName);
|
||||||
statement.setString(2, backpack);
|
statement.setString(2, backpack);
|
||||||
@ -92,7 +99,9 @@ public class MysqlFunctions {
|
|||||||
public static Inventory getBackpackInv(final String playerName, final String backpack) throws SQLException {
|
public static Inventory getBackpackInv(final String playerName, final String backpack) throws SQLException {
|
||||||
Inventory returnInv = null;
|
Inventory returnInv = null;
|
||||||
try {
|
try {
|
||||||
final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
String url = plugin.getUrl()+"?"
|
||||||
|
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
||||||
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
final PreparedStatement state = conn.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
|
final PreparedStatement state = conn.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
@ -118,7 +127,9 @@ public class MysqlFunctions {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
String url = plugin.getUrl()+"?"
|
||||||
|
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
||||||
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
final PreparedStatement state = conn.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
|
final PreparedStatement state = conn.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
|
@ -2,9 +2,9 @@ name: RealBackpacks
|
|||||||
main: cn.citycraft.plugins.RealBackpacks
|
main: cn.citycraft.plugins.RealBackpacks
|
||||||
version: 1.6.5
|
version: 1.6.5
|
||||||
author: Slayr288,喵♂呜
|
author: Slayr288,喵♂呜
|
||||||
softdepend: [Vault]
|
softdepend: [Vault,BVLib]
|
||||||
commands:
|
commands:
|
||||||
rb:
|
rb:
|
||||||
description: Main commands.
|
description: Main commands.
|
||||||
aliases: [realbackpacks, realb, rbs]
|
aliases: [realbackpacks, realb, rbs]
|
||||||
permissions:
|
permissions:
|
||||||
|
Loading…
Reference in New Issue
Block a user