Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.

Commit 5130bc0

Browse files
author
CaptainBern
committed
yey
1 parent fa1947d commit 5130bc0

24 files changed

+936
-276
lines changed
Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,94 @@
11
package me.captainbern.animationlib;
22

3+
import me.captainbern.animationlib.command.CommandInfo;
4+
import me.captainbern.animationlib.command.CommandSource;
5+
import me.captainbern.animationlib.command.ICommand;
6+
import me.captainbern.animationlib.command.User;
7+
import org.bukkit.ChatColor;
8+
import org.bukkit.block.Block;
9+
import org.bukkit.command.BlockCommandSender;
10+
import org.bukkit.command.Command;
11+
import org.bukkit.command.CommandSender;
12+
import org.bukkit.entity.Player;
313
import org.bukkit.plugin.java.JavaPlugin;
414

15+
import java.util.logging.Level;
16+
517
public class AnimationLib extends JavaPlugin {
618

719
private static AnimationLib instance;
8-
public static final String LOG_PREFIX = "[AnimationLib] ";
20+
21+
public static final ModuleLogger LOGGER = new ModuleLogger("AnimationLib");
922

1023
public void onEnable(){
1124
instance = this;
1225

1326
getLogger().info("Enabled");
1427
}
1528

16-
/**
17-
* Used when players would activate this through console or something
18-
*/
19-
public static void main(String[] args){
20-
System.out.print("This is a library for Bukkit, place it in your plugins folder!");
29+
@Override
30+
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
31+
String permissionPrefix = "animationlib.debug.";
32+
String commandPath = "me.captainbern.animationlib.command.commands.Command";
33+
ICommand cmd = null;
34+
35+
User user = null;
36+
Block sBlock = null;
37+
38+
if(sender instanceof Player){
39+
40+
user = new User((Player) sender);
41+
42+
}else if(sender instanceof BlockCommandSender){
43+
44+
BlockCommandSender bCmdSender = (BlockCommandSender) sender;
45+
sBlock = bCmdSender.getBlock();
46+
47+
LOGGER.log(Level.INFO, "CommandBlock at {0}, {1}, {2} issued BackPacks++ command: /{3}", new Object[]
48+
{
49+
sBlock.getX(), sBlock.getY(), sBlock.getZ(), command.getName()
50+
});
51+
52+
}
53+
54+
CommandSource source = new CommandSource(sender);
55+
56+
try {
57+
58+
cmd = (ICommand) this.getClassLoader().loadClass(commandPath + command.getName()).newInstance();
59+
60+
} catch (Exception e) {
61+
LOGGER.log(Level.WARNING, "Failed to execute {0} command!", command.getName());
62+
return true;
63+
}
64+
65+
if(user != null && !user.isAuthorized(cmd, permissionPrefix)){
66+
user.sendMessage(ChatColor.RED + "You don't have permission to execute this command.");
67+
LOGGER.log(Level.INFO, "Player {0} issued AnimationLib (debug) command: /{1}", new Object[]{user.getBase().getName(), command.getName()});
68+
return true;
69+
}
70+
71+
//run the command
72+
try{
73+
if(user != null){
74+
cmd.run(getServer(), user, new CommandInfo(command, args));
75+
return true;
76+
}else{
77+
cmd.run(getServer(), source, new CommandInfo(command, args));
78+
return true;
79+
}
80+
}catch(Exception e){
81+
e.printStackTrace();
82+
}
83+
84+
return true;
2185
}
2286

2387
public static AnimationLib getInstance(){
88+
if(instance == null) {
89+
LOGGER.warning("Instance is null!");
90+
return null;
91+
}
2492
return instance;
2593
}
2694
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.captainbern.animationlib;
2+
3+
import me.captainbern.animationlib.utils.LogicUtil;
4+
import me.captainbern.animationlib.utils.StringUtil;
5+
import org.bukkit.Bukkit;
6+
7+
import java.util.logging.Level;
8+
import java.util.logging.LogRecord;
9+
import java.util.logging.Logger;
10+
11+
public class ModuleLogger extends Logger{
12+
13+
private final String[] modulePath;
14+
private final String prefix;
15+
16+
public ModuleLogger(String... modulePath) {
17+
this(Bukkit.getLogger(), modulePath);
18+
}
19+
20+
public ModuleLogger(Logger parent, String... modulePath) {
21+
super(StringUtil.join(modulePath, "."), null);
22+
this.setParent(parent);
23+
this.setLevel(Level.ALL);
24+
this.modulePath = modulePath;
25+
StringBuilder builder = new StringBuilder();
26+
for (String module : modulePath) {
27+
builder.append("[").append(module).append("] ");
28+
}
29+
this.prefix = builder.toString();
30+
}
31+
32+
public ModuleLogger getModule(String... path) {
33+
return new ModuleLogger(this.getParent(), LogicUtil.appendArray(this.modulePath, path));
34+
}
35+
36+
@Override
37+
public void log(LogRecord logRecord) {
38+
logRecord.setMessage(this.prefix + logRecord.getMessage());
39+
super.log(logRecord);
40+
}
41+
}

src/main/java/me/captainbern/animationlib/animations/BlockAnimation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected void broadcastAnimation(Block block, short damage) {
2727
throw new NumberFormatException("Damage needs to be between 0 and 9!");
2828
}
2929

30-
Packet packet = new Packet(PacketType.BLOCK_BREAK_ANIMATION);
30+
Packet packet = new Packet(PacketType.PLAY.Server.BLOCK_BREAK_ANIMATION);
3131
packet.write("a", RandGen.nextInt());
3232
packet.write("b", block.getX());
3333
packet.write("c", block.getY());
@@ -37,7 +37,7 @@ protected void broadcastAnimation(Block block, short damage) {
3737
sendPacketNearby(block.getLocation(), Arrays.asList(packet), this, block);
3838

3939
}catch(Exception e){
40-
Bukkit.getLogger().warning(AnimationLib.LOG_PREFIX + "Something went wrong while crafting the Packet55BlockBreakAnimation packet! (BLOCK_BREAK)");
40+
AnimationLib.LOGGER.warning("Something went wrong while crafting the Packet55BlockBreakAnimation packet! (BLOCK_BREAK)");
4141
e.printStackTrace();
4242
}
4343
}
@@ -66,6 +66,6 @@ private static void sendPacketNearby(Location loc, Collection<Packet> packets, B
6666
}
6767

6868
protected void broadcastAnimation(Block block, short damage){
69-
throw new UnsupportedOperationException(AnimationLib.LOG_PREFIX + "Unimplemented animation");
69+
throw new UnsupportedOperationException("Unimplemented animation");
7070
}
7171
}

0 commit comments

Comments
 (0)