Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @pastieorg | status | Running Blind This is Pastie.
- ShareBrowseToolsHelpAbout
- Document@2x Chain_link@2x Arrow_down@2x Spiral_paper@2x A A A
- Java 1.12.2012 Report abuse
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411
- 412
- 413
- 414
- 415
- 416
- 417
- 418
- 419
- 420
- 421
- 422
- 423
- 424
- 425
- 426
- 427
- 428
- 429
- 430
- 431
- 432
- 433
- 434
- 435
- 436
- 437
- 438
- 439
- 440
- 441
- 442
- 443
- 444
- 445
- 446
- 447
- 448
- 449
- 450
- 451
- 452
- 453
- 454
- 455
- 456
- 457
- 458
- 459
- 460
- 461
- 462
- 463
- 464
- 465
- 466
- 467
- 468
- 469
- 470
- 471
- 472
- 473
- 474
- 475
- 476
- 477
- 478
- 479
- 480
- 481
- 482
- 483
- 484
- 485
- 486
- 487
- 488
- 489
- 490
- 491
- 492
- 493
- 494
- 495
- 496
- 497
- 498
- 499
- 500
- 501
- 502
- 503
- 504
- 505
- 506
- 507
- 508
- 509
- 510
- 511
- 512
- 513
- 514
- 515
- 516
- 517
- 518
- 519
- 520
- 521
- 522
- 523
- 524
- 525
- 526
- 527
- 528
- 529
- 530
- 531
- 532
- 533
- 534
- 535
- 536
- 537
- 538
- 539
- 540
- 541
- 542
- 543
- 544
- 545
- 546
- 547
- 548
- 549
- 550
- 551
- 552
- 553
- 554
- 555
- 556
- 557
- 558
- 559
- 560
- 561
- 562
- 563
- 564
- 565
- 566
- 567
- 568
- 569
- 570
- 571
- 572
- 573
- 574
- 575
- 576
- 577
- 578
- 579
- 580
- 581
- 582
- 583
- 584
- 585
- 586
- 587
- 588
- 589
- 590
- 591
- 592
- 593
- 594
- 595
- 596
- 597
- 598
- 599
- 600
- 601
- 602
- 603
- 604
- 605
- 606
- 607
- 608
- 609
- 610
- 611
- 612
- 613
- 614
- 615
- 616
- 617
- 618
- 619
- 620
- 621
- 622
- 623
- 624
- 625
- 626
- 627
- 628
- 629
- 630
- 631
- 632
- 633
- 634
- 635
- 636
- 637
- 638
- 639
- 640
- 641
- 642
- 643
- 644
- 645
- 646
- 647
- 648
- 649
- 650
- 651
- 652
- 653
- 654
- 655
- 656
- 657
- 658
- 659
- 660
- 661
- 662
- 663
- 664
- 665
- 666
- 667
- 668
- 669
- 670
- 671
- 672
- 673
- 674
- 675
- 676
- 677
- 678
- 679
- 680
- 681
- 682
- 683
- 684
- 685
- 686
- 687
- 688
- 689
- 690
- 691
- 692
- 693
- 694
- 695
- 696
- 697
- 698
- 699
- 700
- 701
- 702
- 703
- 704
- 705
- 706
- 707
- 708
- 709
- 710
- 711
- 712
- 713
- 714
- 715
- 716
- 717
- 718
- 719
- 720
- 721
- 722
- 723
- 724
- 725
- 726
- 727
- 728
- 729
- 730
- 731
- 732
- 733
- 734
- 735
- 736
- 737
- 738
- 739
- 740
- 741
- 742
- 743
- 744
- 745
- 746
- 747
- 748
- 749
- 750
- 751
- 752
- 753
- 754
- 755
- 756
- 757
- 758
- 759
- 760
- 761
- 762
- 763
- 764
- 765
- 766
- 767
- 768
- 769
- 770
- 771
- 772
- 773
- 774
- 775
- 776
- 777
- 778
- 779
- 780
- 781
- 782
- 783
- 784
- 785
- 786
- 787
- 788
- 789
- 790
- 791
- 792
- 793
- 794
- 795
- 796
- 797
- 798
- 799
- 800
- 801
- 802
- 803
- 804
- 805
- 806
- 807
- 808
- 809
- 810
- 811
- 812
- 813
- 814
- 815
- 816
- 817
- 818
- 819
- 820
- 821
- 822
- 823
- 824
- 825
- 826
- 827
- 828
- 829
- 830
- 831
- 832
- 833
- 834
- 835
- 836
- 837
- 838
- // Add your package name here...
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.io.StringWriter;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.Field;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Set;
- import java.util.concurrent.atomic.AtomicBoolean;
- import java.util.logging.Logger;
- import org.bukkit.ChatColor;
- import org.bukkit.Server;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.command.PluginCommand;
- import org.bukkit.command.SimpleCommandMap;
- import org.bukkit.configuration.Configuration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.permissions.Permissible;
- import org.bukkit.permissions.Permission;
- import org.bukkit.permissions.PermissionAttachment;
- import org.bukkit.permissions.PermissionAttachmentInfo;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.SimplePluginManager;
- import org.bukkit.scheduler.BukkitScheduler;
- import org.json.simple.JSONObject;
- import org.json.simple.parser.JSONParser;
- import org.json.simple.parser.ParseException;
- /**
- *
- * @author V10lator
- * @version 1.4
- * website: http://forums.bukkit.org/threads/autoupdate-update-your-plugins.84421/
- *
- */
- public class AutoUpdate implements Runnable, Listener, CommandExecutor, CommandSender
- {
- /*
- * Configuration:
- *
- * delay = The delay this class checks for new updates. This time is in ticks (1 tick = 1/20 second).
- * bukitdevSlug = The bukkitDev Slug. Leave empty for autodetection (uses plugin.getName().toLowerCase()).
- * COLOR_INFO = The default text color.
- * COLOR_OK = The text color for positive messages.
- * COLOR_ERROR = The text color for error messages.
- */
- private long delay = 216000L;
- private String bukkitdevSlug = "";
- private final ChatColor COLOR_INFO = ChatColor.BLUE;
- private final ChatColor COLOR_OK = ChatColor.GREEN;
- private final ChatColor COLOR_ERROR = ChatColor.RED;
- private boolean debug = true;
- /*
- * End of configuration.
- *
- * !!! Don't change anything below if you don't know what you are doing !!!
- *
- * WARNING: If you change anything below you loose support.
- * Also you have to replace every "http://forums.bukkit.org/threads/autoupdate-update-your-plugins.84421/" with a link to your
- * plugin and change the version to something unique (like adding -<yourName>).
- */
- private final String version = "1.4";
- private final Plugin plugin;
- private int pid = -1;
- private final String av;
- private Configuration config;
- boolean enabled = false;
- private final AtomicBoolean lock = new AtomicBoolean(false);
- private boolean needUpdate = false;
- private boolean updatePending = false;
- private String updateURL;
- private String updateVersion;
- private String pluginURL;
- private String type;
- private ArrayList<CommandExecutor> otherUpdaters;
- /**
- * This will use your main configuration (config.yml).
- * Use this in onEnable().
- * @param plugin The instance of your plugins main class.
- * @throws Exception
- */
- public AutoUpdate(Plugin plugin) throws Exception
- {
- this(plugin, plugin.getConfig());
- }
- /**
- * This will use a custom configuration.
- * Use this in onEnable().
- * @param plugin The instance of your plugins main class.
- * @param config The configuration to use.
- * @throws Exception
- */
- public AutoUpdate(Plugin plugin, Configuration config) throws Exception
- {
- if(plugin == null)
- throw new Exception("Plugin can not be null");
- if(!plugin.isEnabled())
- throw new Exception("Plugin not enabled");
- this.plugin = plugin;
- av = plugin.getDescription().getVersion();
- if(bukkitdevSlug == null || bukkitdevSlug.equals(""))
- bukkitdevSlug = plugin.getName();
- bukkitdevSlug = bukkitdevSlug.toLowerCase();
- if(delay < 72000L)
- {
- plugin.getLogger().info("[AutoUpdate] delay < 72000 ticks not supported. Setting delay to 72000.");
- delay = 72000L;
- }
- setConfig(config);
- registerCommand();
- plugin.getServer().getPluginManager().registerEvents(this, plugin);
- }
- /**
- * Use this to restart the main task.
- * This is useful after scheduler.cancelTasks(plugin); for example.
- */
- public boolean restartMainTask()
- {
- try
- {
- ResetTask rt = new ResetTask(enabled);
- rt.setPid(plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, rt, 0L, 1L));
- return enabled;
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- return false;
- }
- }
- private boolean checkState(boolean newState, boolean restart)
- {
- if(enabled != newState)
- {
- enabled = newState;
- plugin.getLogger().info("[AutoUpdate] v"+version+(enabled ? " enabled" : " disabled")+"!");
- if(restart)
- return restartMainTask();
- }
- return enabled;
- }
- private class ResetTask implements Runnable
- {
- private int pid;
- private final boolean restart;
- private ResetTask(boolean restart)
- {
- this.restart = restart;
- }
- private void setPid(int pid)
- {
- this.pid = pid;
- }
- public void run()
- {
- try
- {
- if(!lock.compareAndSet(false, true))
- return;
- BukkitScheduler bs = plugin.getServer().getScheduler();
- if(bs.isQueued(AutoUpdate.this.pid) || bs.isCurrentlyRunning(AutoUpdate.this.pid))
- bs.cancelTask(AutoUpdate.this.pid);
- if(restart)
- AutoUpdate.this.pid = bs.scheduleAsyncRepeatingTask(plugin, AutoUpdate.this, 5L, delay);
- else
- AutoUpdate.this.pid = -1;
- lock.set(false);
- bs.cancelTask(pid);
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- }
- /**
- * This will overwrite the pre-saved configuration.
- * use this after reloadConfig(), for example.
- * This will use your main configuration (config.yml).
- * This will call {@link #restartMainTask()} internally.
- * @throws FileNotFoundException
- */
- public void resetConfig() throws FileNotFoundException
- {
- setConfig(plugin.getConfig());
- }
- /**
- * This will overwrite the pre-saved configuration.
- * use this after config.load(file), for example.
- * This will use a custom configuration.
- * This will call {@link #restartMainTask()} internally.
- * @param config The new configuration to use.
- * @throws FileNotFoundException
- */
- public void setConfig(Configuration config) throws FileNotFoundException
- {
- if(config == null)
- throw new FileNotFoundException("Config can not be null");
- try
- {
- if(!lock.compareAndSet(false, true))
- {
- ConfigSetter cf = new ConfigSetter(config);
- cf.setPid(plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, cf, 0L, 1L));
- }
- else
- {
- setConfig2(config);
- lock.set(false);
- }
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- private class ConfigSetter implements Runnable
- {
- private final Configuration config;
- private int pid;
- private ConfigSetter(Configuration config)
- {
- this.config = config;
- }
- private void setPid(int pid)
- {
- this.pid = pid;
- }
- public void run()
- {
- if(!lock.compareAndSet(false, true))
- return;
- setConfig2(config);
- lock.set(false);
- plugin.getServer().getScheduler().cancelTask(pid);
- }
- }
- private void setConfig2(Configuration config)
- {
- if(!config.isSet("AutoUpdate"))
- config.set("AutoUpdate", true);
- checkState(config.getBoolean("AutoUpdate"), true);
- }
- /**
- * This is internal stuff.
- * Don't call this directly!
- */
- public void run()
- {
- if(!plugin.isEnabled())
- {
- plugin.getServer().getScheduler().cancelTask(pid);
- return;
- }
- try
- {
- while(!lock.compareAndSet(false, true))
- {
- try
- {
- Thread.sleep(1L);
- }
- catch(InterruptedException e)
- {
- }
- continue;
- }
- try
- {
- InputStreamReader ir;
- URL url = new URL("http://api.bukget.org/api2/bukkit/plugin/"+bukkitdevSlug+"/latest");
- HttpURLConnection con = (HttpURLConnection)url.openConnection();
- con.connect();
- int res = con.getResponseCode();
- if(res != 200)
- {
- if(debug)
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SyncMessageDelayer(null, new String[] {"[AutoUpdate] WARNING: Bukget returned "+res}));
- lock.set(false);
- return;
- }
- ir = new InputStreamReader(con.getInputStream());
- String nv;
- try
- {
- JSONParser jp = new JSONParser();
- Object o = jp.parse(ir);
- if(!(o instanceof JSONObject))
- {
- ir.close();
- lock.set(false);
- return;
- }
- JSONObject jo = (JSONObject)o;
- jo = (JSONObject)jo.get("versions");
- nv = (String)jo.get("version");
- if(av.equals(nv) || (updateVersion != null && updateVersion.equals(nv)))
- {
- ir.close();
- pluginURL = null;
- lock.set(false);
- return;
- }
- updateURL = (String)jo.get("download");
- pluginURL = (String)jo.get("link");
- updateVersion = nv;
- type = (String)jo.get("type");
- needUpdate = true;
- ir.close();
- }
- catch(ParseException e)
- {
- lock.set(false);
- printStackTraceSync(e, true);
- ir.close();
- return;
- }
- final String[] out = new String[] {
- "["+plugin.getName()+"] New "+type+" available!",
- "If you want to update from "+av+" to "+updateVersion+" use /update "+plugin.getName(),
- "See "+pluginURL+" for more information."
- };
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SyncMessageDelayer(null, out));
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
- {
- public void run()
- {
- String[] rout = new String[3];
- for(int i = 0; i < 3; i++)
- rout[i] = COLOR_INFO+out[i];
- for(Player p: plugin.getServer().getOnlinePlayers())
- if(hasPermission(p, "autoupdate.announce"))
- p.sendMessage(rout);
- }
- });
- }
- catch(Exception e)
- {
- printStackTraceSync(e, true);
- }
- lock.set(false);
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- /**
- * This is internal stuff.
- * Don't call this directly!
- */
- @EventHandler(priority = EventPriority.MONITOR)
- public void adminJoin(PlayerJoinEvent event)
- {
- try
- {
- if(!enabled || !lock.compareAndSet(false, true))
- return;
- Player p = event.getPlayer();
- String[] out;
- if(needUpdate)
- {
- if(hasPermission(p, "autoupdate.announce"))
- {
- out = new String[] {
- COLOR_INFO+"["+plugin.getName()+"] New "+type+" available!",
- COLOR_INFO+"If you want to update from "+av+" to "+updateVersion+" use /update "+plugin.getName(),
- COLOR_INFO+"See "+pluginURL+" for more information."
- };
- }
- else
- out = null;
- }
- else if(updatePending)
- {
- if(hasPermission(p, "autoupdate.announce"))
- {
- out = new String[] {
- COLOR_INFO+"Please restart the server to finish the update of "+plugin.getName(),
- COLOR_INFO+"See "+pluginURL+" for more information."
- };
- }
- else
- out = null;
- }
- else
- out = null;
- lock.set(false);
- if(out != null)
- plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new SyncMessageDelayer(p.getName(), out));
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- private class SyncMessageDelayer implements Runnable
- {
- private final String p;
- private final String[] msgs;
- private SyncMessageDelayer(String p, String[] msgs)
- {
- this.p = p;
- this.msgs = msgs;
- }
- public void run()
- {
- try
- {
- if(p != null)
- {
- Player p = plugin.getServer().getPlayerExact(this.p);
- if(p != null)
- for(String msg: msgs)
- if(msg != null)
- p.sendMessage(msg);
- }
- else
- {
- Logger log = plugin.getLogger();
- for(String msg: msgs)
- if(msg != null)
- log.info(msg);
- }
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- }
- private void registerCommand()
- {
- try
- {
- SimplePluginManager pm = (SimplePluginManager)plugin.getServer().getPluginManager();
- Field f = SimplePluginManager.class.getDeclaredField("commandMap");
- f.setAccessible(true);
- SimpleCommandMap cm = (SimpleCommandMap)f.get(pm);
- f.setAccessible(false);
- if(cm.getCommand("update") == null) // First!
- {
- Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
- c.setAccessible(true);
- PluginCommand cmd = c.newInstance("update", plugin);
- c.setAccessible(false);
- cmd.setExecutor(this);
- cm.register("update", cmd);
- otherUpdaters = new ArrayList<CommandExecutor>();
- }
- else
- plugin.getServer().dispatchCommand(this, "update [REGISTER]");
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- /**
- * This is internal stuff.
- * Don't call this directly!
- */
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- try
- {
- if(args.length > 0)
- {
- if(args[0].equals("[REGISTER]"))
- {
- otherUpdaters.add((CommandExecutor)sender);
- return true;
- }
- if(!plugin.getName().equalsIgnoreCase(args[0]))
- {
- informOtherUpdaters(sender, args);
- return true;
- }
- }
- else
- informOtherUpdaters(sender, args);
- update(sender);
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- return true;
- }
- private void informOtherUpdaters(CommandSender sender, String[] args)
- {
- try
- {
- if(otherUpdaters != null)
- for(CommandExecutor ou: otherUpdaters)
- ou.onCommand(sender, null, null, args);
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- private void update(CommandSender sender)
- {
- if(!hasPermission(sender, "autoupdate.update."+plugin.getName()))
- {
- sender.sendMessage(COLOR_ERROR+plugin.getName()+": You are not allowed to update me!");
- return;
- }
- final BukkitScheduler bs = plugin.getServer().getScheduler();
- final String pn = sender instanceof Player ? ((Player)sender).getName() : null;
- bs.scheduleAsyncDelayedTask(plugin, new Runnable()
- {
- public void run()
- {
- try
- {
- while(!lock.compareAndSet(false, true))
- {
- try
- {
- Thread.sleep(1L);
- }
- catch(InterruptedException e)
- {
- }
- }
- String out;
- try
- {
- File to = new File(plugin.getServer().getUpdateFolderFile(), updateURL.substring(updateURL.lastIndexOf('/')+1, updateURL.length()));
- File tmp = new File(to.getPath()+".au");
- if(!tmp.exists())
- {
- plugin.getServer().getUpdateFolderFile().mkdirs();
- tmp.createNewFile();
- }
- URL url = new URL(updateURL);
- InputStream is = url.openStream();
- OutputStream os = new FileOutputStream(tmp);
- byte[] buffer = new byte[4096];
- int fetched;
- while((fetched = is.read(buffer)) != -1)
- os.write(buffer, 0, fetched);
- is.close();
- os.flush();
- os.close();
- if(to.exists())
- to.delete();
- tmp.renameTo(to);
- out = COLOR_OK+plugin.getName()+" ready! Restart server to finish the update.";
- needUpdate = false;
- updatePending = true;
- updateURL = type = null;
- }
- catch(Exception e)
- {
- out = COLOR_ERROR+plugin.getName()+" failed to update!";
- printStackTraceSync(e, true);
- }
- bs.scheduleSyncDelayedTask(plugin, new SyncMessageDelayer(pn, new String[] {out}));
- lock.set(false);
- }
- catch(Throwable t)
- {
- printStackTraceSync(t, false);
- }
- }
- });
- }
- private void printStackTraceSync(Throwable t, boolean expected)
- {
- BukkitScheduler bs = plugin.getServer().getScheduler();
- try
- {
- String prefix = "[AutoUpdate] ";
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- t.printStackTrace(pw);
- String[] sts = sw.toString().replace("\r", "").split("\n");
- String[] out;
- if(expected)
- out = new String[sts.length+25];
- else
- out = new String[sts.length+27];
- out[0] = prefix;
- out[1] = prefix+"Internal error!";
- out[2] = prefix+"If this bug hasn't been reported please open a ticket at http://forums.bukkit.org/threads/autoupdate-update-your-plugins.84421/";
- out[3] = prefix+"Include the following into your bug report:";
- out[4] = prefix+" ======= SNIP HERE =======";
- int i = 5;
- for(; i-5 < sts.length; i++)
- out[i] = prefix+sts[i-5];
- out[++i] = prefix+" ======= DUMP =======";
- out[++i] = prefix+"version : "+version;
- out[++i] = prefix+"delay : "+delay;
- out[++i] = prefix+"bukkitdevSlug : "+bukkitdevSlug;
- out[++i] = prefix+"COLOR_INFO : "+COLOR_INFO.name();
- out[++i] = prefix+"COLO_OK : "+COLOR_OK.name();
- out[++i] = prefix+"COLOR_ERROR : "+COLOR_ERROR.name();
- out[++i] = prefix+"pid : "+pid;
- out[++i] = prefix+"av : "+av;
- out[++i] = prefix+"config : "+config;
- out[++i] = prefix+"lock : "+lock.get();
- out[++i] = prefix+"needUpdate : "+needUpdate;
- out[++i] = prefix+"updatePending : "+updatePending;
- out[++i] = prefix+"UpdateUrl : "+updateURL;
- out[++i] = prefix+"updateVersion : "+updateVersion;
- out[++i] = prefix+"pluginURL : "+pluginURL;
- out[++i] = prefix+"type : "+type;
- out[++i] = prefix+" ======= SNIP HERE =======";
- out[++i] = prefix;
- if(!expected)
- {
- out[++i] = prefix+"DISABLING UPDATER!";
- out[++i] = prefix;
- }
- bs.scheduleSyncDelayedTask(plugin, new SyncMessageDelayer(null, out));
- }
- catch(Throwable e) //This prevents endless loops.
- {
- e.printStackTrace();
- }
- if(!expected)
- {
- bs.cancelTask(pid);
- bs.scheduleAsyncDelayedTask(plugin, new Runnable()
- {
- public void run()
- {
- while(!lock.compareAndSet(false, true))
- {
- try
- {
- Thread.sleep(1L);
- }
- catch(InterruptedException e)
- {
- }
- }
- pid = -1;
- config = null;
- needUpdate = updatePending = enabled = false;
- updateURL = updateVersion = pluginURL = type = null;
- lock.set(false);
- }
- });
- }
- }
- private boolean hasPermission(Permissible player, String node)
- {
- if(player.isPermissionSet(node))
- return player.hasPermission(node);
- while(node.contains("."))
- {
- node = node.substring(0, node.lastIndexOf("."));
- if(player.isPermissionSet(node))
- return player.hasPermission(node);
- if(player.isPermissionSet(node+".*"))
- return player.hasPermission(node+".*");
- }
- if(player.isPermissionSet("*"))
- return player.hasPermission("*");
- return player.isOp();
- }
- /**
- * Use this to enable/disable debugging mode at runtime.
- * @param mode True if you want to enable it, false otherwise.
- */
- public void setDebug(boolean mode)
- {
- debug = mode;
- }
- /**
- * Use this to get the debugging mode.
- * @return True if enabled, false otherwise.
- */
- public boolean getDebug()
- {
- return debug;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public PermissionAttachment addAttachment(Plugin arg0) {
- return null;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public PermissionAttachment addAttachment(Plugin arg0, int arg1) {
- return null;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public PermissionAttachment addAttachment(Plugin arg0, String arg1, boolean arg2) {
- return null;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public PermissionAttachment addAttachment(Plugin arg0, String arg1, boolean arg2, int arg3) {
- return null;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public Set<PermissionAttachmentInfo> getEffectivePermissions() {
- return null;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public boolean hasPermission(String arg0) {
- return false;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public boolean hasPermission(Permission arg0) {
- return false;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public boolean isPermissionSet(String arg0) {
- return false;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public boolean isPermissionSet(Permission arg0) {
- return false;
- }
- /**
- * This is a dummy. Don't use
- */
- public void recalculatePermissions() {}
- /**
- * This is a dummy. Don't use
- */
- public void removeAttachment(PermissionAttachment arg0) {}
- /**
- * This is a dummy. Don't use
- * @return false
- */
- public boolean isOp() {
- return false;
- }
- /**
- * This is a dummy. Don't use
- */
- public void setOp(boolean arg0) {}
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public String getName() {
- return null;
- }
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public Server getServer() {
- return null;
- }
- /**
- * This is a dummy. Don't use
- */
- public void sendMessage(String arg0) {}
- /**
- * This is a dummy. Don't use
- * @return null
- */
- public void sendMessage(String[] arg0) {}
- }
- 20861 characters / 838 lines
- Advertising from Carbon:
- Be nice. :-) Use Pastie for good, not evil.
- Legal Created by
- Josh Goebel Monitored by
- New Relic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement