mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 18:45:31 +01:00
Merge pull request #5 from mibby/master
Few 'Quality of Life' improvements.
This commit is contained in:
commit
35f18e947a
@ -38,6 +38,15 @@ import com.Acrobot.ChestShop.Signs.RestrictedSign;
|
|||||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||||
import com.Acrobot.ChestShop.Updater.Updater;
|
import com.Acrobot.ChestShop.Updater.Updater;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Marker;
|
||||||
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
|
import org.apache.logging.log4j.core.LoggerContext;
|
||||||
|
import org.apache.logging.log4j.core.config.LoggerConfig;
|
||||||
|
import org.apache.logging.log4j.core.filter.AbstractFilter;
|
||||||
|
import org.apache.logging.log4j.message.Message;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -82,6 +91,7 @@ public class ChestShop extends JavaPlugin {
|
|||||||
Configuration.pairFileAndClass(loadFile("config.yml"), Properties.class);
|
Configuration.pairFileAndClass(loadFile("config.yml"), Properties.class);
|
||||||
Configuration.pairFileAndClass(loadFile("local.yml"), Messages.class);
|
Configuration.pairFileAndClass(loadFile("local.yml"), Messages.class);
|
||||||
|
|
||||||
|
turnOffDatabaseLogging();
|
||||||
handleMigrations();
|
handleMigrations();
|
||||||
|
|
||||||
itemDatabase = new ItemDatabase();
|
itemDatabase = new ItemDatabase();
|
||||||
@ -115,6 +125,46 @@ public class ChestShop extends JavaPlugin {
|
|||||||
startUpdater();
|
startUpdater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void turnOffDatabaseLogging() {
|
||||||
|
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||||
|
org.apache.logging.log4j.core.config.Configuration config = ctx.getConfiguration();
|
||||||
|
LoggerConfig loggerConfig = config.getLoggerConfig("");
|
||||||
|
|
||||||
|
loggerConfig.addFilter(new AbstractFilter() {
|
||||||
|
@Override
|
||||||
|
public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, String msg, Object... params) {
|
||||||
|
return filter(logger.getName(), level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, Object msg, Throwable t) {
|
||||||
|
return filter(logger.getName(), level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result filter(org.apache.logging.log4j.core.Logger logger, Level level, Marker marker, Message msg, Throwable t) {
|
||||||
|
return filter(logger.getName(), level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result filter(LogEvent event) {
|
||||||
|
return filter(event.getLoggerName(), event.getLevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result filter(String classname, Level level) {
|
||||||
|
if (level.isAtLeastAsSpecificAs(Level.ERROR) && !classname.contains("SqliteDatabaseType")) {
|
||||||
|
return Result.NEUTRAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classname.contains("SqliteDatabaseType") || classname.contains("TableUtils")) {
|
||||||
|
return Result.DENY;
|
||||||
|
} else {
|
||||||
|
return Result.NEUTRAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void handleMigrations() {
|
private void handleMigrations() {
|
||||||
File versionFile = loadFile("version");
|
File versionFile = loadFile("version");
|
||||||
YamlConfiguration previousVersion = YamlConfiguration.loadConfiguration(versionFile);
|
YamlConfiguration previousVersion = YamlConfiguration.loadConfiguration(versionFile);
|
||||||
|
@ -63,6 +63,9 @@ public class SignBreak implements Listener {
|
|||||||
public static void onSignBreak(BlockBreakEvent event) {
|
public static void onSignBreak(BlockBreakEvent event) {
|
||||||
if (!canBlockBeBroken(event.getBlock(), event.getPlayer())) {
|
if (!canBlockBeBroken(event.getBlock(), event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
if (isSign(event.getBlock())) {
|
||||||
|
event.getBlock().getState().update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +121,6 @@ public class SignBreak implements Listener {
|
|||||||
boolean canBeBroken = true;
|
boolean canBeBroken = true;
|
||||||
|
|
||||||
for (Sign sign : attachedSigns) {
|
for (Sign sign : attachedSigns) {
|
||||||
sign.update();
|
|
||||||
|
|
||||||
if (!canBeBroken || !ChestShopSign.isValid(sign)) {
|
if (!canBeBroken || !ChestShopSign.isValid(sign)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -27,18 +27,6 @@ public class PlayerConnect implements Listener {
|
|||||||
String playerName = NameUtil.stripUsername(playerDTO.getName());
|
String playerName = NameUtil.stripUsername(playerDTO.getName());
|
||||||
UUID uuid = NameManager.getUUID(playerName);
|
UUID uuid = NameManager.getUUID(playerName);
|
||||||
|
|
||||||
if (uuid != null && !playerDTO.getUniqueId().equals(uuid)) {
|
|
||||||
Bukkit.getScheduler().runTask(ChestShop.getPlugin(), new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Bukkit.getPlayer(playerDTO.getUniqueId()).kickPlayer("[ChestShop]" +
|
|
||||||
"Unfortunately, this username was already used by " +
|
|
||||||
"another player.");
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
NameManager.storeUsername(playerDTO);
|
NameManager.storeUsername(playerDTO);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user