mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 04:25:14 +01:00
- Fixed database
- Made it a bit quicker at startup - Added protection against Creepers & TNT
This commit is contained in:
parent
7b6d7d59bd
commit
83a7bbcb6c
@ -20,7 +20,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.LinkedList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,6 +37,7 @@ public class ChestShop extends JavaPlugin {
|
|||||||
private static Server server;
|
private static Server server;
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
blockBreak blockBreak = new blockBreak();
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
|
||||||
//Yep, set up our folder!
|
//Yep, set up our folder!
|
||||||
@ -46,14 +47,18 @@ public class ChestShop extends JavaPlugin {
|
|||||||
Config.setUp();
|
Config.setUp();
|
||||||
|
|
||||||
//Register our events
|
//Register our events
|
||||||
pm.registerEvent(Event.Type.BLOCK_BREAK, new blockBreak(), Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.SIGN_CHANGE, new signChange(), Event.Priority.Normal, this);
|
pm.registerEvent(Event.Type.SIGN_CHANGE, new signChange(), Event.Priority.Normal, this);
|
||||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, new playerInteract(), Event.Priority.Highest, this);
|
pm.registerEvent(Event.Type.PLAYER_INTERACT, new playerInteract(), Event.Priority.Highest, this);
|
||||||
pm.registerEvent(Event.Type.PLUGIN_ENABLE, new pluginEnable(), Event.Priority.Monitor, this);
|
pm.registerEvent(Event.Type.PLUGIN_ENABLE, new pluginEnable(), Event.Priority.Monitor, this);
|
||||||
pm.registerEvent(Event.Type.PLUGIN_DISABLE, new pluginDisable(), Event.Priority.Monitor, this);
|
pm.registerEvent(Event.Type.PLUGIN_DISABLE, new pluginDisable(), Event.Priority.Monitor, this);
|
||||||
pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, new blockBreak(), Event.Priority.Normal, this);
|
|
||||||
pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, new blockBreak(), Event.Priority.Normal, this);
|
if(Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)){
|
||||||
|
pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, blockBreak, Event.Priority.Normal, this);
|
||||||
|
pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, blockBreak, Event.Priority.Normal, this);
|
||||||
|
pm.registerEvent(Event.Type.ENTITY_EXPLODE, new entityExplode(), Event.Priority.Normal, this);
|
||||||
|
}
|
||||||
|
|
||||||
description = this.getDescription(); //Description of the plugin
|
description = this.getDescription(); //Description of the plugin
|
||||||
server = getServer(); //Setting out server variable
|
server = getServer(); //Setting out server variable
|
||||||
@ -65,7 +70,6 @@ public class ChestShop extends JavaPlugin {
|
|||||||
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) {
|
if (Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) {
|
||||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
|
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Generator(), 300L, (long) Config.getDouble(Property.STATISTICS_PAGE_GENERATION_INTERVAL) * 20L);
|
||||||
}
|
}
|
||||||
DB = database.getDatabase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Now set up our logging to file!
|
//Now set up our logging to file!
|
||||||
@ -97,12 +101,12 @@ public class ChestShop extends JavaPlugin {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Database database;
|
private static Database database;
|
||||||
|
|
||||||
private void setupDB() {
|
private void setupDB() {
|
||||||
database = new Database(this) {
|
database = new Database(this) {
|
||||||
protected java.util.List<Class<?>> getDatabaseClasses() {
|
protected java.util.List<Class<?>> getDatabaseClasses() {
|
||||||
List<Class<?>> list = new LinkedList<Class<?>>();
|
List<Class<?>> list = new ArrayList<Class<?>>();
|
||||||
list.add(Transaction.class);
|
list.add(Transaction.class);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -117,8 +121,10 @@ public class ChestShop extends JavaPlugin {
|
|||||||
config.getString("database.password"),
|
config.getString("database.password"),
|
||||||
config.getString("database.isolation"),
|
config.getString("database.isolation"),
|
||||||
false,
|
false,
|
||||||
false
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DB = database.getDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,6 +23,8 @@ public class Transaction {
|
|||||||
private float price;
|
private float price;
|
||||||
private long sec;
|
private long sec;
|
||||||
|
|
||||||
|
public Transaction() {}
|
||||||
|
|
||||||
public float getAveragePricePerItem() {
|
public float getAveragePricePerItem() {
|
||||||
return price / amount;
|
return price / amount;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.Acrobot.ChestShop.Listeners;
|
package com.Acrobot.ChestShop.Listeners;
|
||||||
|
|
||||||
import com.Acrobot.ChestShop.Config.Config;
|
|
||||||
import com.Acrobot.ChestShop.Config.Property;
|
|
||||||
import com.Acrobot.ChestShop.Permission;
|
import com.Acrobot.ChestShop.Permission;
|
||||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||||
@ -18,16 +16,16 @@ import org.bukkit.event.block.BlockPistonRetractEvent;
|
|||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class blockBreak extends BlockListener {
|
public class blockBreak extends BlockListener {
|
||||||
private static boolean cancellingBlockBreak(Block block, Player player) {
|
public static boolean cancellingBlockBreak(Block block, Player player) {
|
||||||
if (player != null && Permission.has(player, Permission.ADMIN)) return false;
|
if (player != null && Permission.has(player, Permission.ADMIN)) return false;
|
||||||
|
|
||||||
if(uSign.isSign(block)) block.getState().update();
|
if (uSign.isSign(block)) block.getState().update();
|
||||||
|
|
||||||
Sign sign = uBlock.findRestrictedSign(block);
|
Sign sign = uBlock.findRestrictedSign(block);
|
||||||
if (sign != null) return true;
|
if (sign != null) return true;
|
||||||
|
|
||||||
sign = uBlock.findSign(block);
|
sign = uBlock.findSign(block);
|
||||||
return sign != null && (player == null || (!player.getName().equals(sign.getLine(0)) && !uLongName.stripName(player.getName()).equals(sign.getLine(0))));
|
return sign != null && (player == null || (!uLongName.stripName(player.getName()).equals(sign.getLine(0))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
@ -35,15 +33,15 @@ public class blockBreak extends BlockListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||||
if (!Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return;
|
for (Block b : event.getBlocks()) {
|
||||||
|
if (cancellingBlockBreak(b, null)) {
|
||||||
for (Block b : event.getBlocks()){
|
event.setCancelled(true);
|
||||||
if (cancellingBlockBreak(b, null)) event.setCancelled(true); return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
if (!Config.getBoolean(Property.USE_BUILT_IN_PROTECTION)) return;
|
|
||||||
if (cancellingBlockBreak(event.getRetractLocation().getBlock(), null)) event.setCancelled(true);
|
if (cancellingBlockBreak(event.getRetractLocation().getBlock(), null)) event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
com/Acrobot/ChestShop/Listeners/entityExplode.java
Normal file
20
com/Acrobot/ChestShop/Listeners/entityExplode.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.Acrobot.ChestShop.Listeners;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
|
import org.bukkit.event.entity.EntityListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Acrobot
|
||||||
|
*/
|
||||||
|
public class entityExplode extends EntityListener{
|
||||||
|
public void onEntityExplode(EntityExplodeEvent event){
|
||||||
|
if (event.isCancelled() || event.blockList() == null) return;
|
||||||
|
for(Block block : event.blockList()){
|
||||||
|
if(blockBreak.cancellingBlockBreak(block, null)){
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,8 +5,8 @@ import com.Acrobot.ChestShop.Config.Language;
|
|||||||
import com.Acrobot.ChestShop.Config.Property;
|
import com.Acrobot.ChestShop.Config.Property;
|
||||||
import com.Acrobot.ChestShop.Permission;
|
import com.Acrobot.ChestShop.Permission;
|
||||||
import com.Acrobot.ChestShop.Protection.Default;
|
import com.Acrobot.ChestShop.Protection.Default;
|
||||||
import com.Acrobot.ChestShop.Signs.restrictedSign;
|
|
||||||
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
||||||
|
import com.Acrobot.ChestShop.Signs.restrictedSign;
|
||||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||||
import com.Acrobot.ChestShop.Utils.uLongName;
|
import com.Acrobot.ChestShop.Utils.uLongName;
|
||||||
import com.Acrobot.ChestShop.Utils.uSign;
|
import com.Acrobot.ChestShop.Utils.uSign;
|
||||||
@ -57,9 +57,9 @@ public class playerInteract extends PlayerListener {
|
|||||||
|
|
||||||
lastTransactionTime.put(player, System.currentTimeMillis());
|
lastTransactionTime.put(player, System.currentTimeMillis());
|
||||||
|
|
||||||
String playerName = player.getName();
|
String playerName = uLongName.stripName(player.getName());
|
||||||
|
|
||||||
if (playerName.equals(sign.getLine(0)) || uLongName.stripName(playerName).equals(sign.getLine(0))) {
|
if (playerName.equals(sign.getLine(0))) {
|
||||||
Chest chest1 = uBlock.findChest(sign);
|
Chest chest1 = uBlock.findChest(sign);
|
||||||
if (chest1 == null) {
|
if (chest1 == null) {
|
||||||
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
||||||
|
@ -73,7 +73,7 @@ public class signChange extends BlockListener {
|
|||||||
Boolean isReady = uSign.isValid(line);
|
Boolean isReady = uSign.isValid(line);
|
||||||
|
|
||||||
if (line[0].isEmpty() || (!line[0].startsWith(player.getName()) && !Permission.has(player, Permission.ADMIN))) {
|
if (line[0].isEmpty() || (!line[0].startsWith(player.getName()) && !Permission.has(player, Permission.ADMIN))) {
|
||||||
event.setLine(0, player.getName());
|
event.setLine(0, uLongName.stripName(player.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
line = event.getLines();
|
line = event.getLines();
|
||||||
|
@ -31,7 +31,7 @@ public class Default implements Protection {
|
|||||||
if (sign != null) signLine = sign.getLine(0);
|
if (sign != null) signLine = sign.getLine(0);
|
||||||
if (neighborSign != null) signLine = neighborSign.getLine(0);
|
if (neighborSign != null) signLine = neighborSign.getLine(0);
|
||||||
|
|
||||||
return playerName.equals(signLine) || uLongName.stripName(playerName).equals(signLine);
|
return uLongName.stripName(playerName).equals(signLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean protect(String name, Block block) {
|
public boolean protect(String name, Block block) {
|
||||||
|
@ -185,6 +185,8 @@ public abstract class Database {
|
|||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(databaseExists) return;
|
||||||
|
|
||||||
//Fire "before drop" event
|
//Fire "before drop" event
|
||||||
try {
|
try {
|
||||||
beforeDropDatabase();
|
beforeDropDatabase();
|
||||||
|
@ -2,7 +2,7 @@ name: ChestShop
|
|||||||
|
|
||||||
main: com.Acrobot.ChestShop.ChestShop
|
main: com.Acrobot.ChestShop.ChestShop
|
||||||
|
|
||||||
version: 3.00 BETA 10
|
version: 3.00 BETA 11
|
||||||
|
|
||||||
|
|
||||||
author: Acrobot
|
author: Acrobot
|
||||||
|
Loading…
Reference in New Issue
Block a user