remove/unregister cube logic+tome of portal logic+config update
This commit is contained in:
parent
e4e8f2aa07
commit
cb62c62831
|
@ -7,10 +7,13 @@ import org.bukkit.block.Sign;
|
|||
import org.bukkit.block.sign.Side;
|
||||
import org.bukkit.block.sign.SignSide;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
@ -41,6 +44,8 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
public static String database;
|
||||
public static String username;
|
||||
public static String password;
|
||||
public static Material cubeTP;
|
||||
public static Material tomePortalReagent;
|
||||
Inventory inv = null;
|
||||
Location clickedCubeLoc;
|
||||
Block clickedBlock;
|
||||
|
@ -65,6 +70,8 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
database = getConfig().getString("MxCraftTP.sqlDB");
|
||||
username = getConfig().getString("MxCraftTP.sqlUser");
|
||||
password = getConfig().getString("MxCraftTP.sqlPass");
|
||||
cubeTP = Material.valueOf(getConfig().getString("MxCraftTP.cubeMaterial"));
|
||||
tomePortalReagent = Material.valueOf(getConfig().getString("MxCraftTP.tomePortalReagent"));
|
||||
|
||||
getLogger().info("Enabled!");
|
||||
}
|
||||
|
@ -78,7 +85,7 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
if (clickedBlock == null) return;
|
||||
World world = getServer().getWorld("world");
|
||||
Block block = world.getBlockAt(clickedBlock.getLocation().getBlockX(), clickedBlock.getLocation().getBlockY()+1, clickedBlock.getLocation().getBlockZ());
|
||||
if(action == Action.RIGHT_CLICK_BLOCK && clickedBlock.getType() == Material.GOLD_BLOCK && block.getState() instanceof Sign){
|
||||
if(action == Action.RIGHT_CLICK_BLOCK && clickedBlock.getType() == cubeTP && block.getState() instanceof Sign){
|
||||
clickedCubeLoc = clickedBlock.getLocation();
|
||||
world = getServer().getWorld("world");
|
||||
block = world.getBlockAt(clickedBlock.getLocation().getBlockX(), clickedBlock.getLocation().getBlockY()+1, clickedBlock.getLocation().getBlockZ());
|
||||
|
@ -91,6 +98,16 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
curCubeZ = clickedBlock.getLocation().getBlockZ();
|
||||
ShowUI(player);
|
||||
}
|
||||
if(action == Action.RIGHT_CLICK_BLOCK){
|
||||
ItemStack mhi = player.getInventory().getItemInMainHand();
|
||||
if(mhi.getItemMeta() != null){
|
||||
String mainhand = mhi.getItemMeta().getDisplayName();
|
||||
if(mainhand.equals("Tome de portail")){
|
||||
ShowUIPortal(player);
|
||||
mhi.setAmount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,6 +124,7 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
|
||||
// register the cube
|
||||
if (e.getRawSlot() == 3){
|
||||
if(SQL.CheckCubeNameExists(curCubeName)){
|
||||
p.sendMessage(MessageFormat.format("§bLe cube {0} existe déjà. Changez le nom.", curCubeName));
|
||||
|
@ -117,6 +135,18 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
// create a tome of portal from a book
|
||||
if (e.getRawSlot() == 4){
|
||||
Inventory pinv = p.getInventory();
|
||||
if(HaveBook(p)){
|
||||
TakeBook(p);
|
||||
pinv.addItem(createGuiItem(Material.ENCHANTED_BOOK, "Tome de portail", "Permets d'aller vers un cube, pas de revenir."));
|
||||
} else {
|
||||
p.sendMessage("§bVous devez posséder un livre pour créer cet objet.");
|
||||
}
|
||||
}
|
||||
|
||||
// unregister a cube
|
||||
if (e.getRawSlot() == 5){
|
||||
if(SQL.CheckCubeNameExists(curCubeName)){
|
||||
SQL.DeleteCubeByName(curCubeName);
|
||||
|
@ -127,17 +157,86 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
// tp to a remote cube
|
||||
if (e.getRawSlot() >= 9){
|
||||
String name = e.getCurrentItem().getItemMeta().getDisplayName();
|
||||
CubeTP(p,name);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreakWithSignOnIt(BlockBreakEvent event){
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) throws SQLException {
|
||||
final Player p = (Player) event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if(block.getState() instanceof Sign){
|
||||
BlockState state = block.getState();
|
||||
Sign sign = (Sign) state;
|
||||
SignSide sside = sign.getSide(Side.FRONT);
|
||||
double x = block.getX();
|
||||
double y = block.getY()-1;
|
||||
double z = block.getZ();
|
||||
if(SQL.CheckCubeByLocation(x, y, z)){
|
||||
String st = sside.getLine(0);
|
||||
SQL.DeleteCubeByName(st);
|
||||
Block cb = p.getWorld().getBlockAt(block.getX(),block.getY()-1, block.getZ());
|
||||
cb.setType(Material.AIR);
|
||||
ItemStack item = new ItemStack(cubeTP, 1);
|
||||
p.getWorld().dropItem(p.getLocation(), item);
|
||||
}
|
||||
}
|
||||
if(block.getType() == Material.GOLD_BLOCK){
|
||||
double x = block.getX();
|
||||
double y = block.getY();
|
||||
double z = block.getZ();
|
||||
if(SQL.CheckCubeByLocation(x, y, z)){
|
||||
Block sb = p.getWorld().getBlockAt(block.getX(),block.getY()+1, block.getZ());
|
||||
BlockState state = sb.getState();
|
||||
Sign sign = (Sign) state;
|
||||
SignSide sside = sign.getSide(Side.FRONT);
|
||||
String st = sside.getLine(0);
|
||||
SQL.DeleteCubeByName(st);
|
||||
sb.setType(Material.AIR);
|
||||
ItemStack item = new ItemStack(Material.OAK_SIGN, 1);
|
||||
p.getWorld().dropItem(p.getLocation(), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event){
|
||||
|
||||
}
|
||||
|
||||
public boolean HaveBook(Player player){
|
||||
boolean hb = false;
|
||||
Inventory pinv = player.getInventory();
|
||||
for(ItemStack i: pinv){
|
||||
if(i != null){
|
||||
if(i.getType() == tomePortalReagent){
|
||||
hb = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hb;
|
||||
}
|
||||
public void TakeBook(Player player){
|
||||
int ba = 0;
|
||||
Inventory pinv = player.getInventory();
|
||||
for(ItemStack i: pinv){
|
||||
if(i != null){
|
||||
if(i.getType() == tomePortalReagent){
|
||||
ba = i.getAmount();
|
||||
i.setAmount(ba-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowUI(Player player) throws SQLException {
|
||||
inv = Bukkit.createInventory(null, 45, "MxCraftTP");
|
||||
World world = getServer().getWorld("world");
|
||||
|
@ -151,12 +250,26 @@ public final class MxCraftTP extends JavaPlugin implements Listener {
|
|||
inv.setItem(1,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(2,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(3,createGuiItem(Material.BOOK, "§bEnregistrer", lore01, lore02));
|
||||
inv.setItem(4,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(4,createGuiItem(Material.ENCHANTED_BOOK, "Tome de portail"));
|
||||
inv.setItem(5,createGuiItem(Material.TNT, "§bRetirer", "§aRetirer de la liste de TP."));
|
||||
inv.setItem(6,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(7,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(8,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(9,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
AddAllCubes(player);
|
||||
player.openInventory(inv);
|
||||
}
|
||||
|
||||
public void ShowUIPortal(Player player) throws SQLException {
|
||||
inv = Bukkit.createInventory(null, 45, "MxCraftTP");
|
||||
inv.setItem(0,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(1,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(2,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(3,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(4,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(5,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(6,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(7,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
inv.setItem(8,createGuiItem(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
AddAllCubes(player);
|
||||
player.openInventory(inv);
|
||||
}
|
||||
|
|
|
@ -71,4 +71,27 @@ public class SQL {
|
|||
ps.setString(1, name);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
public static boolean CheckCubeByLocation(double x, double y, double z) throws SQLException {
|
||||
SQL.connect();
|
||||
PreparedStatement ps = SQL.getConnection().prepareStatement("SELECT * FROM cubetp WHERE x = ? AND y = ? AND z = ?");
|
||||
ps.setDouble(1, x);
|
||||
ps.setDouble(2, y);
|
||||
ps.setDouble(3, z);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
return rs.next();
|
||||
}
|
||||
|
||||
public static String GetCubeNameByLocation(double x, double y, double z) throws SQLException {
|
||||
SQL.connect();
|
||||
PreparedStatement ps = SQL.getConnection().prepareStatement("SELECT * FROM cubetp WHERE x = ? AND y = ? AND z = ?");
|
||||
ps.setDouble(1, x);
|
||||
ps.setDouble(2, y);
|
||||
ps.setDouble(3, z);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs.next()){
|
||||
return rs.getString("name");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
MxCraftTP:
|
||||
# MySQL
|
||||
## MySQL
|
||||
sqlHost: '127.0.0.1'
|
||||
sqlPort: 3306
|
||||
sqlDB: 'changeme'
|
||||
sqlUser: 'changeme'
|
||||
sqlPass: 'changeme'
|
||||
sqlPass: 'changeme'
|
||||
## CubeTP
|
||||
# Material used by the plugin to create a TP cube.
|
||||
# Must be a block. Exemple: 'IRON_BLOCK' 'REDSTONE_BLOCK'
|
||||
# Don't change it if you added tp cube in your world, they will stop working.
|
||||
# I might add an update command in the future, until then, don't change it if it's not a new world.
|
||||
cubeMaterial: 'GOLD_BLOCK'
|
||||
## TomeOfPortal Reagent
|
||||
# Material of the reagent used to create a Tome of Portal.
|
||||
# Any item can be used. You will need one in your inventory to create a Tome of Portal at a tp cube.
|
||||
tomePortalReagent: 'BOOK'
|
|
@ -1,4 +1,4 @@
|
|||
name: MxCraftTP
|
||||
version: 1.0.0
|
||||
version: 1.1.0
|
||||
main: ovh.mxg.mxcrafttp.MxCraftTP
|
||||
api-version: '1.20'
|
Loading…
Reference in New Issue